mirror of https://github.com/pallets/flask.git
Record blueprint registration order.
This commit is contained in:
parent
750ab16364
commit
c09a4317e4
3
CHANGES
3
CHANGES
|
@ -44,6 +44,9 @@ Version 1.0
|
||||||
- Added the ``EXPLAIN_TEMPLATE_LOADING`` config flag which when enabled will
|
- Added the ``EXPLAIN_TEMPLATE_LOADING`` config flag which when enabled will
|
||||||
instruct Flask to explain how it locates templates. This should help
|
instruct Flask to explain how it locates templates. This should help
|
||||||
users debug when the wrong templates are loaded.
|
users debug when the wrong templates are loaded.
|
||||||
|
- Enforce blueprint handling in the order they were registered for template
|
||||||
|
loading.
|
||||||
|
|
||||||
|
|
||||||
Version 0.10.2
|
Version 0.10.2
|
||||||
--------------
|
--------------
|
||||||
|
|
|
@ -472,6 +472,7 @@ class Flask(_PackageBoundObject):
|
||||||
#:
|
#:
|
||||||
#: .. versionadded:: 0.7
|
#: .. versionadded:: 0.7
|
||||||
self.blueprints = {}
|
self.blueprints = {}
|
||||||
|
self._blueprint_order = []
|
||||||
|
|
||||||
#: a place where extensions can store application specific state. For
|
#: a place where extensions can store application specific state. For
|
||||||
#: example this is where an extension could store database engines and
|
#: example this is where an extension could store database engines and
|
||||||
|
@ -903,9 +904,17 @@ class Flask(_PackageBoundObject):
|
||||||
(blueprint, self.blueprints[blueprint.name], blueprint.name)
|
(blueprint, self.blueprints[blueprint.name], blueprint.name)
|
||||||
else:
|
else:
|
||||||
self.blueprints[blueprint.name] = blueprint
|
self.blueprints[blueprint.name] = blueprint
|
||||||
|
self._blueprint_order.append(blueprint)
|
||||||
first_registration = True
|
first_registration = True
|
||||||
blueprint.register(self, options, first_registration)
|
blueprint.register(self, options, first_registration)
|
||||||
|
|
||||||
|
def iter_blueprints(self):
|
||||||
|
"""Iterates over all blueprints by the order they were registered.
|
||||||
|
|
||||||
|
.. versionadded:: 1.0
|
||||||
|
"""
|
||||||
|
return iter(self._blueprint_order)
|
||||||
|
|
||||||
@setupmethod
|
@setupmethod
|
||||||
def add_url_rule(self, rule, endpoint=None, view_func=None, **options):
|
def add_url_rule(self, rule, endpoint=None, view_func=None, **options):
|
||||||
"""Connects a URL rule. Works exactly like the :meth:`route`
|
"""Connects a URL rule. Works exactly like the :meth:`route`
|
||||||
|
|
|
@ -13,7 +13,6 @@ from jinja2 import BaseLoader, Environment as BaseEnvironment, \
|
||||||
|
|
||||||
from .globals import _request_ctx_stack, _app_ctx_stack
|
from .globals import _request_ctx_stack, _app_ctx_stack
|
||||||
from .signals import template_rendered
|
from .signals import template_rendered
|
||||||
from ._compat import itervalues, iteritems
|
|
||||||
|
|
||||||
|
|
||||||
def _default_template_ctx_processor():
|
def _default_template_ctx_processor():
|
||||||
|
@ -81,7 +80,7 @@ class DispatchingJinjaLoader(BaseLoader):
|
||||||
if loader is not None:
|
if loader is not None:
|
||||||
yield self.app, loader
|
yield self.app, loader
|
||||||
|
|
||||||
for blueprint in itervalues(self.app.blueprints):
|
for blueprint in self.app.iter_blueprints():
|
||||||
loader = blueprint.jinja_loader
|
loader = blueprint.jinja_loader
|
||||||
if loader is not None:
|
if loader is not None:
|
||||||
yield blueprint, loader
|
yield blueprint, loader
|
||||||
|
@ -92,7 +91,7 @@ class DispatchingJinjaLoader(BaseLoader):
|
||||||
if loader is not None:
|
if loader is not None:
|
||||||
result.update(loader.list_templates())
|
result.update(loader.list_templates())
|
||||||
|
|
||||||
for name, blueprint in iteritems(self.app.blueprints):
|
for blueprint in self.app.iter_blueprints():
|
||||||
loader = blueprint.jinja_loader
|
loader = blueprint.jinja_loader
|
||||||
if loader is not None:
|
if loader is not None:
|
||||||
for template in loader.list_templates():
|
for template in loader.list_templates():
|
||||||
|
|
Loading…
Reference in New Issue