- @validate(form=spend.new_spend_form, error_handler='index')
- def new(self):
- e = model.Expenditure()
+ def edit(self, id=None):
+ c.users = meta.Session.query(model.User.id, model.User)
+ if id is None:
+ c.title = 'Add a New Expenditure'
+ c.expenditure = model.Expenditure()
+ c.expenditure.spender_id = request.environ['user'].id
+ else:
+ c.title = 'Edit an Expenditure'
+ c.expenditure = meta.Session.query(model.Expenditure).get(id)
+ return render('/spend/index.mako')
+
+ @validate(schema=ExpenditureSchema(), form='edit', variable_decode=True)
+ def update(self, id=None):
+ # Either create a new object, or, if we're editing, get the
+ # old one
+ if id is None:
+ e = model.Expenditure()
+ meta.Session.add(e)
+ else:
+ e = meta.Session.query(model.Expenditure).get(id)
+
+ # Set the fields that were submitted
+ shares = self.form_result.pop('shares')
+ e.amount = Decimal(self.form_result.pop('amount') * 100)