From 18f0c3c367a4dd53aff163f717bb62fb661e8600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Sun, 14 Apr 2013 21:00:24 +0200 Subject: Backport @app.template_test; make the functions in expenses filters/tests --- app/views/expenses.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'app/views/expenses.py') diff --git a/app/views/expenses.py b/app/views/expenses.py index 400876c..269d9bb 100644 --- a/app/views/expenses.py +++ b/app/views/expenses.py @@ -1,4 +1,4 @@ -from flask import Blueprint +from ..flask_extend import Blueprint from flask import render_template, request, url_for, redirect import datetime, decimal @@ -26,25 +26,23 @@ def calc_month_exp(year, month): return MonthExpense(datetime.date(year, month, 1), exps) -@mod.context_processor -def inject_funs(): - def prev_date(exp): - if exp.date.month == 1: - return { "year": exp.date.year - 1, "month": 12 } - else: - return { "year": exp.date.year, "month": exp.date.month - 1 } - - def next_date(exp): - if exp.date.month == 12: - return { "year": exp.date.year + 1, "month": 1 } - else: - return { "year": exp.date.year, "month": exp.date.month + 1} - - def is_last(exp): - return exp.date >= datetime.date.today().replace(day = 1) +@mod.app_template_filter() +def prev_date(exp): + if exp.date.month == 1: + return { "year": exp.date.year - 1, "month": 12 } + else: + return { "year": exp.date.year, "month": exp.date.month - 1 } +@mod.app_template_filter() +def next_date(exp): + if exp.date.month == 12: + return { "year": exp.date.year + 1, "month": 1 } + else: + return { "year": exp.date.year, "month": exp.date.month + 1} - return { 'prev_date' : prev_date, 'next_date' : next_date, 'is_last': is_last } +@mod.app_template_test("last_date") +def is_last(exp): + return exp.date >= datetime.date.today().replace(day = 1) @mod.app_template_filter("date") def format_date(s): -- cgit v1.2.3