summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--controller.py43
-rwxr-xr-xindex.py2
-rw-r--r--static/css/style.css4
-rw-r--r--templates/menu.mako2
-rw-r--r--templates/page.mako15
-rw-r--r--templates/pages/const.mako26
-rw-r--r--templates/pages/constlist.mako19
-rw-r--r--templates/pages/show.mako12
8 files changed, 107 insertions, 16 deletions
diff --git a/controller.py b/controller.py
index 95dba66..21684ee 100644
--- a/controller.py
+++ b/controller.py
@@ -9,6 +9,7 @@ from helper import appdir
from renderer import render
import datetime, decimal
+import itertools as iter
import operator as op
from sqlalchemy import sql
@@ -134,8 +135,19 @@ class Edit (Add):
raise web.seeother("/")
class Const:
- def GET(self):
- return "Const"
+ dformat = "%m.%Y"
+ def GET(self, id=None):
+ if id is None:
+ d = datetime.date.today()
+
+ current = ConstExpense.of_month(d.month, d.year)
+ old = ConstExpense.query.except_(current).order_by(ConstExpense.start)
+
+ return render("constlist", current = current.order_by(ConstExpense.start).all(), old = old.all())
+
+ else:
+ exp = ConstExpense.get(id)
+ return render("const", exp = exp, dformat = lambda x: x.strftime(self.dformat))
class ConstAdd:
template = "constadd"
@@ -157,7 +169,10 @@ class ConstAdd:
e.expense = decimal.Decimal(f.expense.value)
e.description = f.description.value
- raise web.seeother("/")
+ if int(f.prev.value) != -1:
+ e.prev = ConstExpense.get(f.prev.value)
+
+ raise web.seeother("/const/%s" % e.id)
else:
return render(self.template, form = f)
@@ -165,6 +180,7 @@ class ConstAdd:
return ConstExpense()
def form(self):
+ CE = ConstExpense
return Form(
form.Textbox(
"start",
@@ -197,14 +213,28 @@ class ConstAdd:
form.Dropdown(
"category",
map(op.itemgetter(0), sorted(Category.query.values(Category.name)))
+ ),
+ form.Dropdown(
+ "prev",
+ iter.chain([(-1, '')], ConstExpense.query.order_by(CE.description).values(CE.id, CE.description))
)
)
class ConstEdit (ConstAdd):
template = "constedit"
- def GET(self, id):
- exp = ConstExpense.get(id)
+ def GET(self, id, fromId):
+
+ if id == "from":
+ fromC = ConstExpense.get(fromId)
+
+ exp = ConstExpense()
+ exp.from_dict(fromC.to_dict(exclude=["id", "prev"]))
+ exp.prev = fromC
+ session.commit()
+ else:
+ exp = ConstExpense.get(id)
+
self.get_expense = lambda *x: exp
fvalues = {
@@ -213,7 +243,8 @@ class ConstEdit (ConstAdd):
"months" : str(exp.months),
"expense" : str(exp.expense),
"description" : exp.description,
- "category" : exp.category.name
+ "category" : exp.category.name,
+ "prev" : exp.prev.id if exp.prev else str(-1)
}
f = self.form()
f.fill(fvalues)
diff --git a/index.py b/index.py
index 78d44c9..2b46a35 100755
--- a/index.py
+++ b/index.py
@@ -11,7 +11,9 @@ urls = (
"/add/?", controller.Add,
"/edit/(\d+)", controller.Edit,
"/const/?", controller.Const,
+ "/const/(\d+)", controller.Const,
"/const/add/?", controller.ConstAdd,
+ "/const/add/(from)/(\d+)", controller.ConstEdit,
"/const/edit/(\d+)", controller.ConstEdit,
"/categories", controller.Cat,
"/(\d\d\d\d)/(\d\d?)/?", controller.Show,
diff --git a/static/css/style.css b/static/css/style.css
index 10f2331..a450496 100644
--- a/static/css/style.css
+++ b/static/css/style.css
@@ -79,6 +79,10 @@ img {
vertical-align: middle;
}
+.heading {
+ font-weight: bold;
+}
+
div.detail > .heading {
font-weight: bold;
cursor: pointer;
diff --git a/templates/menu.mako b/templates/menu.mako
index 2d4dc5e..98e5904 100644
--- a/templates/menu.mako
+++ b/templates/menu.mako
@@ -2,7 +2,7 @@
menu = [
("/", "Kosten"),
("/add", "Neu"),
- ("/const/add", "Konstante Kosten"),
+ ("/const", "Konstante Kosten"),
("/categories", "Kategorien")
]
%>
diff --git a/templates/page.mako b/templates/page.mako
index 8e30cf3..e08207c 100644
--- a/templates/page.mako
+++ b/templates/page.mako
@@ -8,3 +8,18 @@ ${next.body()}
## functions
<%def name="heading()">
</%def>
+
+<%def name="left_arrow(target,label)">
+ <a id="left" href=${"/%s" % target | url}>
+ <img src=${"/static/images/arrow_left.png" | url} />
+ <span class="navdate">${label}</span>
+ </a>
+</%def>
+
+<%def name="right_arrow(target,label)">
+ <a id="right" href=${"/%s" % target | url}>
+ <img src=${"/static/images/arrow_right.png" | url} />
+ <span class="navdate">${label}</span>
+ </a>
+</%def>
+
diff --git a/templates/pages/const.mako b/templates/pages/const.mako
new file mode 100644
index 0000000..a65a260
--- /dev/null
+++ b/templates/pages/const.mako
@@ -0,0 +1,26 @@
+<%inherit file="/page.mako" />
+
+<ul class="arrow">
+ <li><span class="heading">Description:</span> ${exp.description}</li>
+ <li><span class="heading">Expense:</span> ${exp.expense}</li>
+ <li><span class="heading">Monthly expense:</span> ${exp.monthly}</li>
+ <li><span class="heading">Start Date:</span> ${dformat(exp.start)}</li>
+ <li><span class="heading">End Date:</span> ${dformat(exp.end)}</li>
+ <li><span class="heading">Occurrence (every x months):</span> ${exp.months}</li>
+</ul>
+<p><a href=${"/const/edit/%s" % exp.id | url}>Edit</a> <a href=${"/const/add/from/%s" % exp.id | url}>Create new based on this</a></p>
+
+<%
+ p = exp.prev
+ if p:
+ context.write(self.left_arrow("const/%s" % p.id, p.description))
+
+ p = exp.next
+ if p:
+ context.write(self.right_arrow("const/%s" % p.id, p.description))
+%>
+
+
+<%def name="heading()">
+ Constant Expense
+</%def>
diff --git a/templates/pages/constlist.mako b/templates/pages/constlist.mako
new file mode 100644
index 0000000..83fd9f3
--- /dev/null
+++ b/templates/pages/constlist.mako
@@ -0,0 +1,19 @@
+<%inherit file="/page.mako" />
+
+<h2>Current</h2>
+<ul class="arrow">
+ % for c in current:
+ <li><a href=${"/const/%s" % c.id | url}>${c.description} (${c.expense})</a></li>
+ % endfor
+</ul>
+
+<h2>Outdated</h2>
+<ul class="arrow">
+ % for c in old:
+ <li><a href=${"/const/%s" % c.id | url}>${c.description} (${c.expense})</a></li>
+ % endfor
+</ul>
+
+<%def name="heading()">
+ Constant Expenses
+</%def>
diff --git a/templates/pages/show.mako b/templates/pages/show.mako
index 4a8f9ff..ea9f2e2 100644
--- a/templates/pages/show.mako
+++ b/templates/pages/show.mako
@@ -11,7 +11,7 @@
% endfor
<%self:detail name="Constant" sum="${e.constsum}" set="${e.consts}" args="exp">
- <a href=${"/const/edit/%s" % exp.id | url}>${exp.monthly} -- ${exp.description}</a>
+ <a href=${"/const/%s" % exp.id | url}>${exp.monthly} -- ${exp.description}</a>
</%self:detail>
<%self:detail name="In Summa" sum="${e.sum}" set="${e.all}" args="exp">
@@ -26,10 +26,7 @@
else:
date = "%s/%s" % (e.date.year, e.date.month - 1)
%>
-<a id="left" href=${"/" + date | url}>
- <img src=${"/static/images/arrow_left.png" | url} />
- <span class="navdate">${date}</span>
-</a>
+${self.left_arrow(date, date)}
% if not is_last:
<%
@@ -38,10 +35,7 @@
else:
date = "%s/%s" % (e.date.year, e.date.month + len(exps))
%>
- <a id="right" href=${"/" + date | url}>
- <span class="navdate">${date}</span>
- <img src=${"/static/images/arrow_right.png" | url}/>
- </a>
+ ${self.right_arrow(date, date)}
% endif
<%def name="heading()">