summaryrefslogtreecommitdiff
path: root/controller.py
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2011-02-15 05:45:41 +0100
committerRené 'Necoro' Neumann <necoro@necoro.net>2011-02-15 05:45:41 +0100
commit9d1f28ab132626114450b177f6a9dd51107fe577 (patch)
tree66cf8bb1f9702e7d198eb522ecd166fc35751700 /controller.py
parent2e663fa91e1f14c5406fb19fac7e6b2b8d7a64ad (diff)
downloadkosten-9d1f28ab132626114450b177f6a9dd51107fe577.tar.gz
kosten-9d1f28ab132626114450b177f6a9dd51107fe577.tar.bz2
kosten-9d1f28ab132626114450b177f6a9dd51107fe577.zip
Move the 'add from' to the correct place: ConstAdd
Diffstat (limited to 'controller.py')
-rw-r--r--controller.py55
1 files changed, 27 insertions, 28 deletions
diff --git a/controller.py b/controller.py
index 5770440..62eb235 100644
--- a/controller.py
+++ b/controller.py
@@ -158,10 +158,19 @@ class ConstAdd:
template = "constadd"
dformat = "%m.%Y"
- def GET(self):
- return render(self.template, form = self.form())
+ def GET(self, fromId = None):
- def POST(self):
+ f = self.form()
+ if fromId is not None:
+ fromC = ConstExpense.get(fromId)
+
+ fill = self.form_fill(fromC)
+ fill["prev"] = fromC.id
+ f.fill(fill)
+
+ return render(self.template, form = f)
+
+ def POST(self, fromId = None):
f = self.form()
if f.validates():
category = Category.get_by(name = f.category.value)
@@ -186,6 +195,17 @@ class ConstAdd:
def get_expense(self):
return ConstExpense()
+ def form_fill(self, exp):
+ return {
+ "start" : exp.start.strftime(self.dformat),
+ "end" : exp.end.strftime(self.dformat),
+ "months" : str(exp.months),
+ "expense" : str(exp.expense),
+ "description" : exp.description,
+ "category" : exp.category.name,
+ "prev" : exp.prev.id if exp.prev else str(-1)
+ }
+
def form(self):
CE = ConstExpense
@@ -243,38 +263,17 @@ class ConstAdd:
class ConstEdit (ConstAdd):
template = "constedit"
- def GET(self, id, fromId = None):
-
- if id == "from":
- fromC = ConstExpense.get(fromId)
-
- exp = ConstExpense()
- exp.from_dict(fromC.to_dict(exclude=["id", "prev", "next"]))
- exp.prev = fromC
- session.commit()
- else:
- exp = ConstExpense.get(id)
+ def GET(self, id):
+ exp = ConstExpense.get(id)
self.get_expense = lambda *x: exp
- fvalues = {
- "start" : exp.start.strftime(self.dformat),
- "end" : exp.end.strftime(self.dformat),
- "months" : str(exp.months),
- "expense" : str(exp.expense),
- "description" : exp.description,
- "category" : exp.category.name,
- "prev" : exp.prev.id if exp.prev else str(-1)
- }
f = self.form()
- f.fill(fvalues)
+ f.fill(self.form_fill(exp))
return render(self.template, form = f)
- def POST(self, id, fromId = None):
- if id == "from":
- id = fromId
-
+ def POST(self, id):
exp = ConstExpense.get(id)
self.get_expense = lambda *x: exp
return ConstAdd.POST(self)