diff options
author | Marian Sigler <m@qjym.de> | 2012-09-14 01:28:02 +0200 |
---|---|---|
committer | Marian Sigler <m@qjym.de> | 2012-09-14 01:28:02 +0200 |
commit | 97f983b73c5a27cd8785575bf941e66d747cdd82 (patch) | |
tree | 80385aed31b864836c97f64db9c01d31f4f1e4d2 /utils.py | |
parent | d7e62d1166991c0c4c9fa1385ead2bd2058b5b86 (diff) | |
download | web-97f983b73c5a27cd8785575bf941e66d747cdd82.tar.gz web-97f983b73c5a27cd8785575bf941e66d747cdd82.tar.bz2 web-97f983b73c5a27cd8785575bf941e66d747cdd82.zip |
first web stuff
Diffstat (limited to 'utils.py')
-rw-r--r-- | utils.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..2f3b433 --- /dev/null +++ b/utils.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +from functools import wraps +from flask import request, render_template + +# from http://flask.pocoo.org/docs/patterns/viewdecorators/#templating-decorator +def templated(template=None): + def decorator(f): + @wraps(f) + def decorated_function(*args, **kwargs): + template_name = template + if template_name is None: + template_name = request.endpoint \ + .replace('.', '/') + '.html' + ctx = f(*args, **kwargs) + if ctx is None: + ctx = {} + elif not isinstance(ctx, dict): + return ctx + return render_template(template_name, **ctx) + return decorated_function + return decorator |