Example #1
0
def add_investment(account_id):
    form = InvestmentForm()
    account = Account.query.get(account_id)
    if form.validate_on_submit():
        if not form.price.data and form.symbol.data:
            form.price.data = get_current_price(form.symbol.data)
        inv = Investment(name=form.name.data, symbol=form.symbol.data,
                         shares=form.shares.data, price=form.price.data,
                         account=account)
        db.session.add(inv)
        db.session.commit()
        return redirect(url_for('.index'))
    return render_template("add_investment.html", account=account, form=form)
Example #2
0
def edit_investment(investment_id):
    investment = Investment.query.get(investment_id)
    form = InvestmentForm(obj=investment)
    if not form.price.data and form.symbol.data:
        form.price.data = get_current_price(form.symbol.data)
    if form.validate_on_submit():
        investment.name = form.name.data
        investment.symbol = form.symbol.data
        investment.shares = form.shares.data
        investment.price = form.price.data
        db.session.add(investment)
        db.session.commit()
        return redirect(url_for('.index'))
    return render_template("edit_investment.html", investment=investment, form=form)