From b9b9200795b9fe7f6d054f117934e179a44f0224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Tue, 16 Apr 2013 00:21:01 +0200 Subject: Fix templated --- app/utils.py | 14 ++++++++++---- app/views/consts.py | 2 +- app/views/expenses.py | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/utils.py b/app/utils.py index caacea7..67b4897 100644 --- a/app/utils.py +++ b/app/utils.py @@ -2,14 +2,20 @@ from functools import wraps from flask import request, render_template, url_for from flask import redirect as _redirect +def _gen_tpl(endpoint): + return endpoint.replace('.', '/') + '.jinja' + 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('.', '/') + '.jinja' + if template is None: + template_name = _gen_tpl(request.endpoint) + elif template[0] == '.' and request.blueprint is not None: + template_name = _gen_tpl(request.blueprint + template) + else: + template_name = template + ctx = f(*args, **kwargs) if ctx is None: ctx = {} diff --git a/app/views/consts.py b/app/views/consts.py index 441137d..6200bfa 100644 --- a/app/views/consts.py +++ b/app/views/consts.py @@ -75,7 +75,7 @@ def edit(id): return { 'form': form } @mod.route("/add/from/") -@templated("add") +@templated(".add") def add_from(other): exp = ConstExpense() # needed to initialize 'CE.next' diff --git a/app/views/expenses.py b/app/views/expenses.py index c0d9c65..57a777a 100644 --- a/app/views/expenses.py +++ b/app/views/expenses.py @@ -46,7 +46,7 @@ def is_last(exp): return exp.date >= datetime.date.today().replace(day = 1) @mod.route("//") -@templated("show") +@templated(".show") def show_date(year, month): c = calc_month_exp(year, month) return { 'exps' : [c] } -- cgit v1.2.3