def edit(request): session = DBSession() transaction_id = request.matchdict['transaction_id'] transaction = session.query(Transaction).\ filter_by(id=transaction_id).one() form = make_edit_form(request, transaction) try: data = form.validate(request.POST.items()) except ValidationFailure, e: return edit_form(request, e)
def edit_form(request, form=None): if form is None: session = DBSession() transaction_id = request.matchdict['transaction_id'] transaction = session.query(Transaction).\ filter_by(id=transaction_id).one() form = make_edit_form(request, transaction) if transaction.composite: data = transaction.__dict__ data['lines'] = [] for txn in session.query(Transaction).\ filter_by(part_of=transaction_id).all(): data['lines'].append(txn.__dict__) else: data = transaction.__dict__ api = TemplateAPI(request, 'add') bindings = {'api': api, 'form': form, 'data': data} return render_to_response('templates/edit.pt', bindings)