summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2013-04-14 20:16:23 +0200
committerRené 'Necoro' Neumann <necoro@necoro.net>2013-04-14 20:16:23 +0200
commita98445a75c3ac2a46540eee146129f7c77e005d5 (patch)
tree25c916e288fb9aa90e37ce82b0b7b81eaa82a46a /app
parentec08e8522193d01f691c925484fd011dc8fc5ee0 (diff)
downloadkosten-a98445a75c3ac2a46540eee146129f7c77e005d5.tar.gz
kosten-a98445a75c3ac2a46540eee146129f7c77e005d5.tar.bz2
kosten-a98445a75c3ac2a46540eee146129f7c77e005d5.zip
Simplify some things
Diffstat (limited to 'app')
-rw-r--r--app/views/expenses.py40
1 files changed, 18 insertions, 22 deletions
diff --git a/app/views/expenses.py b/app/views/expenses.py
index 312d0c2..400876c 100644
--- a/app/views/expenses.py
+++ b/app/views/expenses.py
@@ -15,9 +15,6 @@ def expense_form(obj=None):
form.category.query = Category.query.order_by("name")
return form
-def is_last(exp):
- return exp.date >= datetime.date.today().replace(day = 1)
-
def calc_month_exp(year, month):
ssum = func.sum(SingleExpense.expense)
query = SingleExpense.of_month(month, year)
@@ -29,19 +26,25 @@ def calc_month_exp(year, month):
return MonthExpense(datetime.date(year, month, 1), exps)
-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.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(exps):
- def _next_date(exp):
- if exp.date.month == 13 - len(exps):
+ 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 + len(exps) }
- return _next_date
+ return { "year": exp.date.year, "month": exp.date.month + 1}
+
+ def is_last(exp):
+ return exp.date >= datetime.date.today().replace(day = 1)
+
+
+ return { 'prev_date' : prev_date, 'next_date' : next_date, 'is_last': is_last }
@mod.app_template_filter("date")
def format_date(s):
@@ -50,17 +53,10 @@ def format_date(s):
else:
return "%(year)s/%(month)s" % s
-def render_show(exps, is_last):
- return render_template("pages/show.jinja",
- exps = exps, is_last = is_last,
- prev_date = prev_date,
- next_date = next_date(exps))
-
-
@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_show([c], is_last(c))
+ return render_template("pages/show.jinja", exps = [c])
@mod.route("/")
def show(year = None, month = None):
@@ -72,7 +68,7 @@ def show(year = None, month = None):
else:
second = calc_month_exp(d.year, d.month - 1)
- return render_show([first, second], is_last(first))
+ return render_template("pages/show.jinja", exps = [first, second])
@mod.route("/edit/<int:id>", methods=("GET", "POST"))
def edit(id):