summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2010-05-12 10:44:15 +0200
committerRené 'Necoro' Neumann <necoro@necoro.net>2010-05-12 10:44:15 +0200
commit01531c519a4a93b985a8494d28f951c746683f56 (patch)
treef51692a74057fbb65196254df9158fbdb505f959
parent585e2750154a4b6816bb2a67aca02b1640a5c7d6 (diff)
downloadkosten-01531c519a4a93b985a8494d28f951c746683f56.tar.gz
kosten-01531c519a4a93b985a8494d28f951c746683f56.tar.bz2
kosten-01531c519a4a93b985a8494d28f951c746683f56.zip
Show more details
-rw-r--r--controller.py14
-rw-r--r--model.py22
-rw-r--r--static/js/show.js2
-rw-r--r--templates/show.mako23
4 files changed, 42 insertions, 19 deletions
diff --git a/controller.py b/controller.py
index 4e488dd..b853f2a 100644
--- a/controller.py
+++ b/controller.py
@@ -32,18 +32,14 @@ class Show:
month = int(month)
ssum = sql.functions.sum(SingleExpense.expense)
- csum = sql.functions.sum(ConstExpense.monthly)
+ query = SingleExpense.of_month(month, year)
- query = SingleExpense.of_month(month, year).\
- group_by(SingleExpense.category_id).\
- values(SingleExpense.category_id, ssum)
+ result = query.group_by(SingleExpense.category_id).\
+ values(SingleExpense.category_id, ssum)
- exps = [CatExpense(Category.query.get(c), s) for c,s in query]
+ exps = [CatExpense(Category.query.get(c), s, query.filter(SingleExpense.category_id == c)) for c,s in result]
- 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)
+ return MonthExpense(datetime.date(int(year), int(month), 1), exps)
def render(self, exps):
return render("show", exps = exps)
diff --git a/model.py b/model.py
index 2a16bde..d8cf91d 100644
--- a/model.py
+++ b/model.py
@@ -82,7 +82,7 @@ class ConstExpense (Expense):
next = OneToOne('ConstExpense', inverse = 'prev')
prev = ManyToOne('ConstExpense')
- monthly = ColumnProperty(lambda c: sql.cast(c.expense / c.months, ExpNum), deferred = True)
+ monthly = ColumnProperty(lambda c: sql.cast(c.expense / c.months, ExpNum))
@classmethod
def of_month (cls, month, year):
@@ -92,14 +92,28 @@ class ConstExpense (Expense):
#
# Work entities (not stored in DB)
#
-CatExpense = namedtuple('CatExpense', 'cat expense')
+class CatExpense (namedtuple('CatExpense', 'cat expense exps')):
+ __slots__ = ()
+
+ @property
+ def all (self):
+ return self.exps.order_by(SingleExpense.day).all()
-class MonthExpense (namedtuple('MonthExpense', 'date const catexps')):
+class MonthExpense (namedtuple('MonthExpense', 'date catexps')):
__slots__ = ()
@property
+ def constsum (self):
+ c = ConstExpense.of_month(self.date.month, self.date.year)
+ return c.value(sql.functions.sum(ConstExpense.monthly)) or None
+
+ @property
+ def consts (self):
+ return ConstExpense.of_month(self.date.month, self.date.year).all()
+
+ @property
def sum (self):
- return self.const + sum(x.expense for x in self.catexps)
+ return self.constsum + sum(x.expense for x in self.catexps)
@property
def all (self):
diff --git a/static/js/show.js b/static/js/show.js
index c0b6d12..0c2fd8a 100644
--- a/static/js/show.js
+++ b/static/js/show.js
@@ -1,6 +1,6 @@
$(document).ready(function(){
$(".details_heading").click(function() {
- $(this).next().toggle()
+ $(this).next().next().toggle()
})
$(".details").hide()
diff --git a/templates/show.mako b/templates/show.mako
index 97c2731..88d802c 100644
--- a/templates/show.mako
+++ b/templates/show.mako
@@ -5,12 +5,24 @@
<h2>${get_d(e)}</h2>
% endif
% for c in e.catexps:
- <strong>${c.cat.name}</strong> ${c.expense}<br>
+ <strong class="details_heading">${c.cat.name}</strong> ${c.expense}<br/>
+ <div class="details">
+ <ul>
+ % for exp in c.all:
+ <li>${exp.day}.${exp.month}. -- ${exp.description}: ${exp.expense} </li>
+ % endfor
+ </ul>
+ </div>
% endfor
- <strong>Constant:</strong> ${e.const}<br>
- <strong>In Summa:</strong> ${e.sum}<br><br>
-
- <h3 class="details_heading">Details</h3>
+ <strong class="details_heading">Constant:</strong> ${e.constsum}<br/>
+ <div class="details">
+ <ul>
+ % for c in e.consts:
+ <li>${c.monthly} -- ${c.description}</li>
+ % endfor
+ </ul>
+ </div>
+ <strong class="details_heading">In Summa:</strong> ${e.sum}<br />
<div class="details">
<ul>
% for exp in e.all:
@@ -18,6 +30,7 @@
% endfor
</ul>
</div>
+ <br/>
% endfor
<%def name="heading()">