Skip to content
Myr

Ignore before_render_template return values

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Alexander Pantyukhin · committed by Markus Unterwaditzer · parent 883f82f · Browse files · 2 files+2 added−33 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+2 added−33 removed

  • tests:+0 added−20 removed
  • other:+2 added−13 removed

2 files+2 added−33 removed

modified:flask/templating.py+2 added-13 removed
99 unmodified lines
100 return list(result)101102103def _render(template, context, app):104 """Renders the template and fires signals.104 """Renders the template and fires the signal"""105106 It is possible to override render template in the before_render_template signal.107 It can be done only if exactly one receiver and it return not None result."""108109 brt_resp = before_render_template.send(app, template=template, context=context)106 before_render_template.send(app, template=template, context=context)110 111 overrides = [rv for _, rv in brt_resp if rv is not None]112 if len(overrides) == 1:113 return overrides[0]114 elif len(overrides) > 1:115 raise RuntimeError('More than one before_render_template signal '116 'returned data')117107 rv = template.render(context)108 template_rendered.send(app, template=template, context=context)109 return rv110
30 unmodified lines
modified:tests/test_signals.py-20 removed
68 unmodified lines
69 assert rv.data == b'<h1>43</h1>'70 finally:71 flask.before_render_template.disconnect(record, app)7273def test_before_render_template_signal_not_None_result_render_skip_render_template():74 app = flask.Flask(__name__)7576 @app.route('/')77 def index():78 return flask.render_template('simple_template.html', whiskey=42)7980 recorded = []8182 def record(sender, template, context):83 recorded.append((template, context))84 return 'Not template string'8586 flask.before_render_template.connect(record, app)87 try:88 rv = app.test_client().get('/')89 assert rv.data == b'Not template string'90 finally:91 flask.before_render_template.disconnect(record, app) 9273def test_request_signals():74 app = flask.Flask(__name__)75 calls = []76
126 unmodified lines