Browse Source

Ignore before_render_template return values

pull/1509/head
Alexander Pantyukhin 10 years ago committed by Markus Unterwaditzer
parent
commit
5e12748d0e
  1. 15
      flask/templating.py
  2. 20
      tests/test_signals.py

15
flask/templating.py

@ -101,20 +101,9 @@ class DispatchingJinjaLoader(BaseLoader):
def _render(template, context, app):
"""Renders the template and fires signals.
It is possible to override render template in the before_render_template signal.
It can be done only if exactly one receiver and it return not None result."""
brt_resp = before_render_template.send(app, template=template, context=context)
overrides = [rv for _, rv in brt_resp if rv is not None]
if len(overrides) == 1:
return overrides[0]
elif len(overrides) > 1:
raise RuntimeError('More than one before_render_template signal '
'returned data')
"""Renders the template and fires the signal"""
before_render_template.send(app, template=template, context=context)
rv = template.render(context)
template_rendered.send(app, template=template, context=context)
return rv

20
tests/test_signals.py

@ -70,26 +70,6 @@ def test_before_render_template():
finally:
flask.before_render_template.disconnect(record, app)
def test_before_render_template_signal_not_None_result_render_skip_render_template():
app = flask.Flask(__name__)
@app.route('/')
def index():
return flask.render_template('simple_template.html', whiskey=42)
recorded = []
def record(sender, template, context):
recorded.append((template, context))
return 'Not template string'
flask.before_render_template.connect(record, app)
try:
rv = app.test_client().get('/')
assert rv.data == b'Not template string'
finally:
flask.before_render_template.disconnect(record, app)
def test_request_signals():
app = flask.Flask(__name__)
calls = []

Loading…
Cancel
Save