diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2013-04-15 00:29:18 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2013-04-15 00:29:18 +0200 |
commit | 9fb5ed666cf428ae24ddcb1d5a306660526162be (patch) | |
tree | e11c6381ab21cf0d63b0af73102209d532de7a28 /app | |
parent | 18f0c3c367a4dd53aff163f717bb62fb661e8600 (diff) | |
download | kosten-9fb5ed666cf428ae24ddcb1d5a306660526162be.tar.gz kosten-9fb5ed666cf428ae24ddcb1d5a306660526162be.tar.bz2 kosten-9fb5ed666cf428ae24ddcb1d5a306660526162be.zip |
Moved the 'date' filter to the top-level
Diffstat (limited to '')
-rw-r--r-- | app/views/__init__.py | 7 | ||||
-rw-r--r-- | app/views/expenses.py | 21 |
2 files changed, 15 insertions, 13 deletions
diff --git a/app/views/__init__.py b/app/views/__init__.py index eed6d0a..d64b945 100644 --- a/app/views/__init__.py +++ b/app/views/__init__.py @@ -20,6 +20,13 @@ def static_url(s): def eur(s): return (u"%s EUR" % s) +@app.template_filter("date") +def format_date(s, format="%Y/%m"): + if hasattr(s, "date"): + return s.date.strftime(format) + else: + return s.strftime(format) + @app.errorhandler(404) def page_not_found (error): return render_template("404.jinja", page = request.path), 404 diff --git a/app/views/expenses.py b/app/views/expenses.py index 269d9bb..512c906 100644 --- a/app/views/expenses.py +++ b/app/views/expenses.py @@ -12,7 +12,7 @@ mod = Blueprint('expenses', __name__) def expense_form(obj=None): form = ExpenseForm(obj=obj) - form.category.query = Category.query.order_by("name") + form.category.query = Category.query.order_by(Category.name) return form def calc_month_exp(year, month): @@ -29,35 +29,30 @@ def calc_month_exp(year, month): @mod.app_template_filter() def prev_date(exp): if exp.date.month == 1: - return { "year": exp.date.year - 1, "month": 12 } + return exp.date.replace(year = exp.date.year - 1, month = 12) else: - return { "year": exp.date.year, "month": exp.date.month - 1 } + return exp.date.replace(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 } + return exp.date.replace(year = exp.date.year + 1, month = 1) else: - return { "year": exp.date.year, "month": exp.date.month + 1} + return exp.date.replace(month = exp.date.month + 1) @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): - if hasattr(s, "date"): - return "%s/%s" % (s.date.year, s.date.month) - else: - return "%(year)s/%(month)s" % s - @mod.route("/<int(fixed_digits=4):year>/<int(fixed_digits=2):month>") def show_date(year, month): c = calc_month_exp(year, month) return render_template("pages/show.jinja", exps = [c]) +mod.add_url_rule("/<path:p>", endpoint = "show_date_str", build_only = True) + @mod.route("/") -def show(year = None, month = None): +def show(): d = datetime.date.today() first = calc_month_exp(d.year, d.month) |