Ejemplo n.º 1
0
def account_new():
    """添加账单条目
    """
    form = AccountForm(request.form)
    if request.method == 'POST' and form.validate():
        account = Account()
        form.populate_obj(account)
        account.funder_id = Person.judge(form.funder.data)
        account.china_yuan = form.transaction_money.data*account.get_forex(form.currency.data)
        db.session.add(account)
        account.save()
        print 'ni'
        flash(u'成功添加账单条目')
        return redirect('/account/%d' % int(account.id))

    return render_template('/account/edit.html', form=form, title=u'添加账单条目')
Ejemplo n.º 2
0
def account_edit(id):
    """编辑账单条目
    
    和添加类似,参加 Person 的实现
    """
    account = Account.query.get(id)
    form = AccountForm(request.form, obj=account)
    if account.funder_id:
        form.funder.data = account.funders.name
    
    if request.method == 'POST' and form.validate():
        form.populate_obj(account)
        account.funder_id = Person.judge(form.funder.data)
        account.china_yuan = form.enter_money.data*account.get_forex(form.currency.data)
        account.save()
        flash(u'成功更新账单条目信息')
        return redirect('/account/%d' % id)
    return render_template('/account/edit.html', form=form, title=u'编辑账单条目')