Added missing decorators for module wide context processors.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
This fixes #25.
authored by Armin Ronacher · committed by Armin Ronacher · parent 7f83790 · Browse files · 2 files·+41 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
2 files+41 added−2 removed
- tests:+23 added−0 removed
- other:+18 added−2 removed
Provenance
- Commit
745638e- Tree
0e17f68- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
7f83790
2 files changed+41 added−2 removed
modified:tests/flask_tests.py+23 added
439 unmodified lines440 assert c.get('/admin/').data == 'the admin'441 assert catched == ['before-app', 'before-admin',442 'after-admin', 'after-app']443 444+ def test_context_processors(self):445+ app = flask.Flask(__name__)446+ admin = flask.Module(__name__, 'admin', url_prefix='/admin')447+ @app.context_processor448+ def inject_all_regualr():449+ return {'a': 1}450+ @admin.context_processor451+ def inject_admin():452+ return {'b': 2}453+ @admin.app_context_processor454+ def inject_all_module():455+ return {'c': 3}456+ @app.route('/')457+ def index():458+ return flask.render_template_string('{{ a }}{{ b }}{{ c }}')459+ @admin.route('/')460+ def index():461+ return flask.render_template_string('{{ a }}{{ b }}{{ c }}')462+ app.register_module(admin)463+ c = app.test_client()464+ assert c.get('/').data == '13'465+ assert c.get('/admin/').data == '123'466+467 def test_late_binding(self):468 app = flask.Flask(__name__)469 admin = flask.Module(__name__, 'admin')470 @admin.route('/')23 unmodified linesmodified:flask.py+18 added-2 removed
463 unmodified lines464 return f465 466 def before_app_request(self, f):467 """Like :meth:`Flask.before_request`. Such a function is executed468- before each request.468+ before each request, even if outside of a module.469 """470 self._record(lambda s: s.app.before_request_funcs471 .setdefault(None, []).append(f))472 return f8 unmodified lines481 return f482 483 def after_app_request(self, f):484 """Like :meth:`Flask.after_request` but for a module. Such a function485- is executed after each request.485+ is executed after each request, even if outside of the module.486 """487 self._record(lambda s: s.app.after_request_funcs488 .setdefault(None, []).append(f))489 return f490 491+ def context_processor(self, f):492+ """Like :meth:`Flask.context_processor` but for a modul. This493+ function is only executed for requests handled by a module.494+ """495+ self._record(lambda s: s.app.template_context_processors496+ .setdefault(self.name, []).append(f))497+ return f498+499+ def app_context_processor(self, f):500+ """Like :meth:`Flask.context_processor` but for a module. Such a501+ function is executed each request, even if outside of the module.502+ """503+ self._record(lambda s: s.app.template_context_processors504+ .setdefault(None, []).append(f))505+ return f506+507 def _record(self, func):508 self._register_events.append(func)509 510 547 unmodified lines