summaryrefslogtreecommitdiffstats
path: root/utils.py
diff options
context:
space:
mode:
authorAlexander Sulfrian <alex@spline.inf.fu-berlin.de>2014-11-19 03:14:29 +0100
committerAlexander Sulfrian <alex@spline.inf.fu-berlin.de>2014-11-19 03:14:29 +0100
commit2c59dcacc2163ac48e36f1fde5fa6b10f769442f (patch)
tree2962def04eb00ce79cc0b490577fb1b5d71c1963 /utils.py
parent4f377e9e70cce40fec9bed51b76d0650d5a750df (diff)
downloadpadlite-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.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/utils.py b/utils.py
index fbec4c9..c424850 100644
--- a/utils.py
+++ b/utils.py
@@ -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):