Declare pillar.current_app before importing other Pillar modules.

This makes it easier/possible to just do "from pillar import current_app"
in submodules.
This commit is contained in:
Sybren A. Stüvel 2017-05-24 15:42:59 +02:00
parent 1f2dd34683
commit 4e268510f2

View File

@ -21,6 +21,18 @@ import pymongo.collection
import pymongo.database import pymongo.database
from werkzeug.local import LocalProxy from werkzeug.local import LocalProxy
# Declare pillar.current_app before importing other Pillar modules.
def _get_current_app():
"""Returns the current application."""
return flask.current_app
current_app: 'PillarServer' = LocalProxy(_get_current_app)
"""the current app, annotated as PillarServer"""
from pillar.api import custom_field_validation from pillar.api import custom_field_validation
from pillar.api.utils import authentication from pillar.api.utils import authentication
import pillar.web.jinja import pillar.web.jinja
@ -622,13 +634,3 @@ class PillarServer(Eve):
schema = self.config['DOMAIN'][resource_name]['schema'] schema = self.config['DOMAIN'][resource_name]['schema']
validator = self.validator(schema, resource_name) validator = self.validator(schema, resource_name)
return validator return validator
def _get_current_app():
"""Returns the current application."""
return flask.current_app
current_app: PillarServer = LocalProxy(_get_current_app)
"""the current app, annotated as PillarServer"""