From 4e268510f277250ae4cdfd175e508231ab86917e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 24 May 2017 15:42:59 +0200 Subject: [PATCH] Declare pillar.current_app before importing other Pillar modules. This makes it easier/possible to just do "from pillar import current_app" in submodules. --- pillar/__init__.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/pillar/__init__.py b/pillar/__init__.py index e2a3b7df..57b1f926 100644 --- a/pillar/__init__.py +++ b/pillar/__init__.py @@ -21,6 +21,18 @@ import pymongo.collection import pymongo.database 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.utils import authentication import pillar.web.jinja @@ -622,13 +634,3 @@ class PillarServer(Eve): schema = self.config['DOMAIN'][resource_name]['schema'] validator = self.validator(schema, resource_name) 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"""