summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--controller.py55
-rwxr-xr-xindex.py2
-rw-r--r--model.py2
3 files changed, 29 insertions, 30 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)
diff --git a/index.py b/index.py
index 2b46a35..e7687e2 100755
--- a/index.py
+++ b/index.py
@@ -13,7 +13,7 @@ urls = (
"/const/?", controller.Const,
"/const/(\d+)", controller.Const,
"/const/add/?", controller.ConstAdd,
- "/const/add/(from)/(\d+)", controller.ConstEdit,
+ "/const/add/from/(\d+)", controller.ConstAdd,
"/const/edit/(\d+)", controller.ConstEdit,
"/categories", controller.Cat,
"/(\d\d\d\d)/(\d\d?)/?", controller.Show,
diff --git a/model.py b/model.py
index b42c02c..9c04e83 100644
--- a/model.py
+++ b/model.py
@@ -79,8 +79,8 @@ class ConstExpense (Expense):
start = ReqField(T.Date, index = True)
end = ReqField(T.Date, index = True)
- next = OneToOne('ConstExpense', inverse = 'prev')
prev = ManyToOne('ConstExpense')
+ next = OneToOne('ConstExpense', inverse = 'prev')
monthly = ColumnProperty(lambda c: sql.cast(c.expense / c.months, ExpNum))