Ignore before_render_template return values

This commit is contained in:
Alexander Pantyukhin 2015-04-07 07:18:15 +00:00 committed by Markus Unterwaditzer
parent 883f82f261
commit 5e12748d0e
2 changed files with 2 additions and 33 deletions

View file

@ -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

View file

@ -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 = []