From 585e2750154a4b6816bb2a67aca02b1640a5c7d6 Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Wed, 12 May 2010 00:12:57 +0200 Subject: Create new form each time --- controller.py | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/controller.py b/controller.py index f3059d4..4e488dd 100644 --- a/controller.py +++ b/controller.py @@ -52,30 +52,6 @@ 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 render("add", form = self.form()) @@ -92,6 +68,32 @@ class Add: else: return render("add", form = f) + @property + def form(self): + return 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)), + )) + ) + class Edit: def GET(self, id): return "Edit " + id -- cgit v1.2.3-70-g09d2