diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2010-05-04 16:07:19 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2010-05-04 16:07:19 +0200 |
commit | fc2b648989cd5afaff3c563dea739e90c19be331 (patch) | |
tree | 6163e99ad09f42423b0899ce74c1918632efedb1 /controller.py | |
parent | 4b4905db5f4123a88dca9f0164a3a35679a9dc13 (diff) | |
download | kosten-fc2b648989cd5afaff3c563dea739e90c19be331.tar.gz kosten-fc2b648989cd5afaff3c563dea739e90c19be331.tar.bz2 kosten-fc2b648989cd5afaff3c563dea739e90c19be331.zip |
First working 'Show'
Diffstat (limited to '')
-rw-r--r-- | controller.py | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/controller.py b/controller.py index 69eaf76..0957692 100644 --- a/controller.py +++ b/controller.py @@ -1,13 +1,47 @@ from __future__ import with_statement import web + +from model import * from helper import appdir from renderer import render +import datetime +from sqlalchemy import sql + class Show: def GET(self, year = '', month = ''): - if year: return "Show %s/%s" % (year, month) - else: return "Show current" + if year: + return self.render([self.calc(year, month)]) + else: + d = datetime.date.today() + + first = self.calc(d.year, d.month) + if d.month == 1: + second = self.calc(d.year - 1, 12) + else: + second = self.calc(d.year, d.month - 1) + + return self.render([first, second]) + + def calc(self, year, month): + + ssum = sql.functions.sum(SingleExpense.expense) + csum = sql.functions.sum(ConstExpense.expense) + + query = SingleExpense.of_month(month, year).\ + group_by(SingleExpense.category_id).\ + values(SingleExpense.category_id, ssum) + + exps = [CatExpense(Category.query.get(c), s) for c,s in query] + + consts = ConstExpense.of_month(month, year).value(csum) + if consts is None: consts = 0 + + return MonthExpense(datetime.date(int(year), int(month), 1), consts, exps) + + def render(self, exps): + return render("show", exps = exps) class Add: def GET(self): |