summaryrefslogtreecommitdiff
path: root/app/views/expenses.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/views/expenses.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/app/views/expenses.py b/app/views/expenses.py
index 57a777a..893c367 100644
--- a/app/views/expenses.py
+++ b/app/views/expenses.py
@@ -27,6 +27,19 @@ def calc_month_exp(year, month):
return MonthExpense(datetime.date(year, month, 1), exps)
+def pie_stuff(exp):
+ expenses = {}
+ for c in exp.catexps:
+ expenses[c.cat.name] = float(c.expense)
+
+ for c in Category.query.order_by(Category.name).all():
+ yield (c.name, expenses.get(c.name, 0.0))
+
+def calc_month_and_pie(year, month):
+ exp = calc_month_exp(year,month)
+ pie = pie_stuff(exp)
+ return (exp, dict(pie))
+
@mod.app_template_filter()
def prev_date(exp):
if exp.date.month == 1:
@@ -58,13 +71,13 @@ mod.add_url_rule("/<path:p>", endpoint = "show_date_str", build_only = True)
def show():
d = datetime.date.today()
- first = calc_month_exp(d.year, d.month)
+ first, pfirst = calc_month_and_pie(d.year, d.month)
if d.month == 1:
- second = calc_month_exp(d.year - 1, 12)
+ second, psecond = calc_month_and_pie(d.year - 1, 12)
else:
- second = calc_month_exp(d.year, d.month - 1)
+ second, psecond = calc_month_and_pie(d.year, d.month - 1)
- return { 'exps' : [first, second] }
+ return { 'exps' : [first, second], 'pies': [pfirst, psecond] }
@mod.route("/edit/<int:id>", methods=("GET", "POST"))
@templated()