diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2010-05-10 21:40:26 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2010-05-10 21:40:26 +0200 |
commit | 7b1b6578bd3f1fbb5f23fb0cb907229a8feb477d (patch) | |
tree | 214fc7e880102a09902e6cbb169785bca0a62d70 | |
parent | e715c36c2b6047f30407412cc1af6b6afb12fd59 (diff) | |
download | kosten-7b1b6578bd3f1fbb5f23fb0cb907229a8feb477d.tar.gz kosten-7b1b6578bd3f1fbb5f23fb0cb907229a8feb477d.tar.bz2 kosten-7b1b6578bd3f1fbb5f23fb0cb907229a8feb477d.zip |
Added the 'add expense' stuff
Diffstat (limited to '')
-rw-r--r-- | controller.py | 46 | ||||
-rw-r--r-- | model.py | 11 | ||||
-rw-r--r-- | templates/add.mako | 14 | ||||
-rw-r--r-- | templates/menu.mako | 1 |
4 files changed, 69 insertions, 3 deletions
diff --git a/controller.py b/controller.py index f9bd27c..2615a9f 100644 --- a/controller.py +++ b/controller.py @@ -1,12 +1,14 @@ from __future__ import with_statement import web +from web import form from model import * from helper import appdir from renderer import render -import datetime +import datetime, decimal +import operator as op from sqlalchemy import sql class Show: @@ -47,8 +49,48 @@ class Show: return render("show", exps = exps) class Add: + + dformat = "%d.%m.%Y" + + form = form.Form( + form.Textbox( + "date", + form.notnull, + value = datetime.date.today().strftime(dformat) + ), + form.Textbox( + "expense", + form.notnull, + ), + form.Textbox( + "description", + form.notnull + ), + form.Dropdown( + "category", + map(op.itemgetter(0), sorted(Category.query.values(Category.name))) + ), + validators = map(lambda x: form.Validator(*x), ( + ("Date Format does not match", lambda f: datetime.datetime.strptime(f.date, Add.dformat)), + ("Not a valid decimal", lambda f: decimal.Decimal(f.expense)), + )) + ) + def GET(self): - return "Add new" + return render("add", form = self.form()) + + def POST(self): + f = self.form() + if f.validates(): + e = SingleExpense(category = Category.get_by(name = f.category.value)) + + e.date = datetime.datetime.strptime(f.date.value, self.dformat) + e.expense = decimal.Decimal(f.expense.value) + e.description = f.description.value + + raise web.seeother(web.url("/")) + else: + return render("add", form = f) class Edit: def GET(self, id): @@ -33,7 +33,6 @@ class Entity (elixir.Entity): # class Category (Entity): - name = Field(T.String(50), unique = True) parent = ManyToOne('Category') @@ -65,6 +64,16 @@ class SingleExpense (Expense): return cls.query.filter(comp) + @property + def date (self): + return datetime.date(self.year, self.month, self.day) + + @date.setter + def date (self, d): + self.year = d.year + self.month = d.month + self.day = d.day + class ConstExpense (Expense): months = ReqField(T.SmallInteger) start = ReqField(T.Date, index = True) diff --git a/templates/add.mako b/templates/add.mako new file mode 100644 index 0000000..ac67404 --- /dev/null +++ b/templates/add.mako @@ -0,0 +1,14 @@ +<%inherit file="/page.mako" /> + +% if not form.valid: + ERROR! +% endif + +<form name="add_expense" method="post"> + ${form.render()} + <input type="submit" /> +</form> + +<%def name="heading()"> + Add new expense +</%def> diff --git a/templates/menu.mako b/templates/menu.mako index 329b255..98e5904 100644 --- a/templates/menu.mako +++ b/templates/menu.mako @@ -1,6 +1,7 @@ <%! menu = [ ("/", "Kosten"), + ("/add", "Neu"), ("/const", "Konstante Kosten"), ("/categories", "Kategorien") ] |