def add_scenario(): checked_title = check_title(request.form['title']) if float(request.form['mezz_debt']) > 0: is_intr_only = to_boolean(request.form['mezz_interest_only']) is_secured = to_boolean(request.form['mezz_secured']) mezz_rate = float(request.form['mezz_rate']) mezz_amort = float(request.form['mezz_amort']) else: is_intr_only = to_boolean('no') is_secured = to_boolean('no') mezz_rate = 1 mezz_amort = 1 scenario = Scenario(checked_title, float(request.form['cash_on_cash']), float(request.form['target_ltv']), float(request.form['mezz_debt']), float(request.form['transfer_cost']), float(request.form['transfer_buyer_share']), float(request.form['recordation_cost']), float(request.form['recordation_buyer_share']), float(request.form['finance']), float(request.form['interest']), float(request.form['amort']), mezz_rate, is_intr_only, is_secured, mezz_amort, float(request.form['income_appr']), float(request.form['apprec_depr']), float(request.form['holding_period']), current_user.id) form = ScenarioForm(obj=scenario) if form.validate(): c = CalcCapRate(scenario.__dict__) result = c.iterate_computation() cap_rate = result['cap_rate'] #print "===cap rate: " + str(cap_rate) scenario.cap_rate = cap_rate db.session.add(scenario) db.session.commit() #flash('New scenario was successfully posted', 'alert alert-info') return redirect(url_for('show_scenarios') + '#results-column') else: print "Advanced calc input not validated." print form.errors return redirect(url_for('show_scenarios'))
def basic_calc(): scenario = Scenario("basic", # title float(request.form['cash_on_cash']), float(request.form['target_ltv']), 0, # mezz_debt 0, # transfer_cost 50, # transfer_buyer_share 0, # recordation_cost 50, # recordation_buyer_share 0, # finance float(request.form['interest']), float(request.form['amort']), 8, # mezz_rate False, # mezz_interest_only False, # mezz_secured 30, # mezz_amort 0, # income_appr 0, # apprec_depr 5) # holding_period form = ScenarioForm(obj=scenario) form.title.data = "basic" # For some reason, not picking this up from scenario if form.validate(): c = CalcCapRate(scenario.__dict__) result = c.iterate_computation() # Convert to percentages for output result.update((i, j*100) for i, j in result.items()) cap_rate = result['cap_rate'] scenario.cap_rate = cap_rate return render_template('basic.html', form=form, scenario=scenario, result=result) else: print "Not Validated." print form.errors return redirect(url_for('basic'))