More docstrings for blueprints.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent dbb9a2e · Browse files · 4 files·+40 added−11 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+40 added−11 removed
- other:+40 added−11 removed
Provenance
- Commit
8617505- Tree
cd85707- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
dbb9a2e
4 files changed+40 added−11 removed
modified:docs/patterns/appfactories.rst+2 added-2 removed
1 unmodified line2 3 Application Factories4 =====================5 6-If you are already using packages and modules for your application7-(:ref:`packages`) there are a couple of really nice ways to further improve6+If you are already using packages and blueprints for your application7+(:ref:`blueprints`) there are a couple of really nice ways to further improve8 the experience. A common pattern is creating the application object when9 the module is imported. But if you move the creation of this object,10 into a function, you can then create multiple instances of this and later.11 64 unmodified linesmodified:docs/api.rst+6 added-3 removed
16 unmodified lines17 :members:18 :inherited-members:19 20 21-Module Objects22---------------21+Blueprint Objects22+-----------------23 24-.. autoclass:: Module24+.. autoclass:: Blueprint25 :members:26 :inherited-members:27 28 Incoming Request Data320 unmodified lines349 ctx = _request_ctx_stack.top350 if ctx is not None:351 return ctx.session352 353+.. autoclass:: flask.blueprints.BlueprintSetupState354+ :members:355+356 Signals357 -------358 359 .. when modifying this list, also update the one in signals.rst56 unmodified linesmodified:docs/quickstart.rst+1 added-2 removed
379 unmodified lines380 /templates381 /hello.html382 383 For templates you can use the full power of Jinja2 templates. Head over384-to the :ref:`templating` section of the documentation or the official385-`Jinja2 Template Documentation384+to the the official `Jinja2 Template Documentation385 <http://jinja.pocoo.org/2/documentation/templates>`_ for more information.386 387 Here is an example template:388 361 unmodified linesmodified:flask/blueprints.py+31 added-4 removed
14 unmodified lines15 16 17 class BlueprintSetupState(object):18 """Temporary holder object for registering a blueprint with the19- application.19+ application. An instance of this class is created by the20+ :meth:`~flask.Blueprint.make_setup_state` method and later passed21+ to all register callback functions.22 """23 24 def __init__(self, blueprint, app, options, first_registration):25+ #: a reference to the current application26 self.app = app27+28+ #: a reference to the blurprint that created this setup state.29 self.blueprint = blueprint30+31+ #: a dictionary with all options that were passed to the32+ #: :meth:`~flask.Flask.register_blueprint` method.33 self.options = options34+35+ #: as blueprints can be registered multiple times with the36+ #: application and not everything wants to be registered37+ #: multiple times on it, this attribute can be used to figure38+ #: out if the blueprint was registered in the past already.39 self.first_registration = first_registration40 41 subdomain = self.options.get('subdomain')42 if subdomain is None:43 subdomain = self.blueprint.subdomain44+45+ #: The subdomain that the blueprint should be active for, `None`46+ #: otherwise.47 self.subdomain = subdomain48 49 url_prefix = self.options.get('url_prefix')50 if url_prefix is None:51 url_prefix = self.blueprint.url_prefix52+53+ #: The prefix that should be used for all URLs defined on the54+ #: blueprint.55 self.url_prefix = url_prefix56 57+ #: A dictionary with URL defaults that is added to each and every58+ #: URL that was defined with the blueprint.59 self.url_defaults = dict(self.blueprint.url_defaults)60 self.url_defaults.update(self.options.get('url_defaults', ()))61 62 def add_url_rule(self, rule, endpoint=None, view_func=None, **options):13 unmodified lines76 view_func, defaults=defaults, **options)77 78 79 class Blueprint(_PackageBoundObject):59- """Represents a blueprint.80+ """Represents a blueprint. A blueprint is an object that records81+ functions that will be called with the82+ :class:`~flask.blueprint.BlueprintSetupState` later to register functions83+ or other things on the main application. See :ref:`blueprints` for more84+ information.85 86 .. versionadded:: 0.787 """88 39 unmodified lines128 func(state)129 return self.record(update_wrapper(wrapper, func))130 131 def make_setup_state(self, app, options, first_registration=False):132+ """Creates an instance of :meth:`~flask.blueprints.BlueprintSetupState`133+ object that is later passed to the register callback functions.134+ Subclasses can override this to return a subclass of the setup state.135+ """136 return BlueprintSetupState(self, app, options, first_registration)137 138 def register(self, app, options, first_registration=False):139 """Called by :meth:`Flask.register_blueprint` to register a blueprint142 unmodified lines282 up from the application.283 284 Otherwise works as the :meth:`~flask.Flask.errorhandler` decorator285 of the :class:`~flask.Flask` object.257-258- .. versionadded:: 0.7286 """287 def decorator(f):288 self.record_once(lambda s: s.app._register_error_handler(289 self.name, code_or_exception, f))2 unmodified lines