Created
August 25, 2012 20:42
-
-
Save plaes/3470780 to your computer and use it in GitHub Desktop.
Flask context decorator for Celery tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def push_context(fn): | |
@wraps(fn) | |
def decorator(*args, **kwargs): | |
app_host = app.config.get('SERVER_NAME') | |
app_root = app.config.get('APPLICATION_ROOT') | |
base_url = 'https://{}/'.format(app_host if app_host else 'localhost') | |
if app_root: | |
base_url += app.root.lstrip('/') | |
app.test_request_context(base_url=base_url).push() | |
return fn(*args, **kwargs) | |
return decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment