From 01444a8e45b7bd5b846ebc1a26afb87ee18f8265 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Tue, 15 Feb 2011 03:19:21 +0100 Subject: More nice things for constant expenses --- controller.py | 43 ++++++++++++++++++++++++++++++++++++------ index.py | 2 ++ static/css/style.css | 4 ++++ templates/menu.mako | 2 +- templates/page.mako | 15 +++++++++++++++ templates/pages/const.mako | 26 +++++++++++++++++++++++++ templates/pages/constlist.mako | 19 +++++++++++++++++++ templates/pages/show.mako | 12 +++--------- 8 files changed, 107 insertions(+), 16 deletions(-) create mode 100644 templates/pages/const.mako create mode 100644 templates/pages/constlist.mako 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 name="left_arrow(target,label)"> + + + ${label} + + + +<%def name="right_arrow(target,label)"> + + + ${label} + + + 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" /> + + +

Edit Create new based on this

+ +<% + 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 + 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" /> + +

Current

+ + +

Outdated

+ + +<%def name="heading()"> + Constant Expenses + 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"> - ${exp.monthly} -- ${exp.description} + ${exp.monthly} -- ${exp.description} <%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) %> - - - ${date} - +${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)) %> - - ${date} - - + ${self.right_arrow(date, date)} % endif <%def name="heading()"> -- cgit v1.2.3-54-g00ecf