Skip to content
Myr

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

2 files+41 added−2 removed

modified:tests/flask_tests.py+23 added
439 unmodified lines
440 assert c.get('/admin/').data == 'the admin'441 assert catched == ['before-app', 'before-admin',442 'after-admin', 'after-app']443444 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'466467 def test_late_binding(self):468 app = flask.Flask(__name__)469 admin = flask.Module(__name__, 'admin')470 @admin.route('/')
23 unmodified lines
modified:flask.py+18 added-2 removed
463 unmodified lines
464 return f465466 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 f
8 unmodified lines
481 return f482483 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 f490491 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 f498499 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 f506507 def _record(self, func):508 self._register_events.append(func)509510
547 unmodified lines