diff options
author | Alexander Sulfrian <alex@spline.inf.fu-berlin.de> | 2014-11-19 03:14:29 +0100 |
---|---|---|
committer | Alexander Sulfrian <alex@spline.inf.fu-berlin.de> | 2014-11-19 03:14:29 +0100 |
commit | 2c59dcacc2163ac48e36f1fde5fa6b10f769442f (patch) | |
tree | 2962def04eb00ce79cc0b490577fb1b5d71c1963 /utils.py | |
parent | 4f377e9e70cce40fec9bed51b76d0650d5a750df (diff) | |
download | padlite-teams-2c59dcacc2163ac48e36f1fde5fa6b10f769442f.tar.gz padlite-teams-2c59dcacc2163ac48e36f1fde5fa6b10f769442f.tar.bz2 padlite-teams-2c59dcacc2163ac48e36f1fde5fa6b10f769442f.zip |
utils: add after_this_request
With after_this_request you can simple set cookies. Used as a decorator,
it registers a function as callback to be executed just before sending
the response to the client. The callback will be executed with the
response object as argument.
Diffstat (limited to 'utils.py')
-rw-r--r-- | utils.py | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -1,5 +1,5 @@ from functools import wraps -from flask import request, render_template +from flask import g, request, render_template from wtforms import Field, ValidationError from widgets import Static @@ -21,6 +21,14 @@ def templated(template=None): return decorated_function return decorator + +def after_this_request(f): + if not hasattr(g, 'after_request_callbacks'): + g.after_request_callbacks = [] + g.after_request_callbacks.append(f) + return f + + class Unique(object): """ validator that checks field uniqueness """ def __init__(self, model, field, message=None): |