Skip to content
Myr

Merge branch 'alexpantyukhin-master'

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

Fix #1390

authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parents cb9f645, a9066a3 · Browse files · 6 files+47 added−2 removed
This commit

State

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

Diff stats

6 files+47 added−2 removed

  • tests:+24 added−0 removed
  • other:+23 added−2 removed

6 files+47 added−2 removed

modified:docs/api.rst+17 added
536 unmodified lines
537538 from flask import template_rendered539 template_rendered.connect(log_template_renders, app)540541.. data:: flask.before_render_template542 :noindex:543544 This signal is sent before template rendering process. The545 signal is invoked with the instance of the template as `template`546 and the context as dictionary (named `context`).547548 Example subscriber::549550 def log_template_renders(sender, template, context, **extra):551 sender.logger.debug('Rendering template "%s" with context %s',552 template.name or 'string template',553 context)554555 from flask import before_render_template556 before_render_template.connect(log_template_renders, app)557558.. data:: request_started559560 This signal is sent when the request context is set up, before561 any request processing happens. Because the request context is already
338 unmodified lines
modified:flask/__init__.py+1 added-1 removed
32 unmodified lines
33# the signals34from .signals import signals_available, template_rendered, request_started, \35 request_finished, got_request_exception, request_tearing_down, \36 appcontext_tearing_down, appcontext_pushed, \37 appcontext_popped, message_flashed37 appcontext_popped, message_flashed, before_render_template3839# We're not exposing the actual json module but a convenient wrapper around40# it.41from . import json
8 unmodified lines
modified:flask/signals.py+1 added
43 unmodified lines
4445# Core signals. For usage examples grep the source code or consult46# the API documentation in docs/api.rst as well as docs/signals.rst47template_rendered = _signals.signal('template-rendered')48before_render_template = _signals.signal('before-render-template')49request_started = _signals.signal('request-started')50request_finished = _signals.signal('request-finished')51request_tearing_down = _signals.signal('request-tearing-down')52got_request_exception = _signals.signal('got-request-exception')
4 unmodified lines
modified:flask/templating.py+3 added-1 removed
10 unmodified lines
11from jinja2 import BaseLoader, Environment as BaseEnvironment, \12 TemplateNotFound1314from .globals import _request_ctx_stack, _app_ctx_stack15from .signals import template_rendered15from .signals import template_rendered, before_render_template161718def _default_template_ctx_processor():19 """Default template context processor. Injects `request`,
81 unmodified lines
101102103def _render(template, context, app):104 """Renders the template and fires the signal"""105106 before_render_template.send(app, template=template, context=context)107 rv = template.render(context)108 template_rendered.send(app, template=template, context=context)109 return rv110
30 unmodified lines
modified:tests/test_signals.py+24 added
44 unmodified lines
45 assert context['whiskey'] == 4246 finally:47 flask.template_rendered.disconnect(record, app)4849def test_before_render_template():50 app = flask.Flask(__name__)5152 @app.route('/')53 def index():54 return flask.render_template('simple_template.html', whiskey=42)5556 recorded = []5758 def record(sender, template, context):59 context['whiskey'] = 4360 recorded.append((template, context))6162 flask.before_render_template.connect(record, app)63 try:64 rv = app.test_client().get('/')65 assert len(recorded) == 166 template, context = recorded[0]67 assert template.name == 'simple_template.html'68 assert context['whiskey'] == 4369 assert rv.data == b'<h1>43</h1>'70 finally:71 flask.before_render_template.disconnect(record, app)7273def test_request_signals():74 app = flask.Flask(__name__)75 calls = []76
126 unmodified lines
modified:CHANGES+1 added
6 unmodified lines
7-----------89(release date to be announced, codename to be selected)1011- Added before_render_template signal.12- Added `**kwargs` to :meth:`flask.Test.test_client` to support passing13 additional keyword arguments to the constructor of14 :attr:`flask.Flask.test_client_class`.15- Added ``SESSION_REFRESH_EACH_REQUEST`` config key that controls the
536 unmodified lines