converted over to using a class in disp.py that defines data about each variable in the form, and use an array of these objects to format the form in templates/index.html -- provides consistency of bootstrap classes and makes it far easier to move items around columns/rows in the future, e.g. when I resign. Also, now retrieve actual values form comparison set data (still have hardcoded cset_id for now), but also stopped using separate vars for items like CBA/TLS, and buried them into the finance_data
This commit is contained in:
68
main.py
68
main.py
@@ -1,11 +1,12 @@
|
||||
# main.py
|
||||
from flask import Flask, render_template, request, redirect, url_for, Response
|
||||
from calc import calculate_savings_depletion
|
||||
from db import init_db, get_finance_data, update_finance, get_budget_data, last_cset_savings_data
|
||||
from db import init_db, get_finance_data, update_finance, get_budget_data, get_comp_set_data
|
||||
from collections import defaultdict
|
||||
from datetime import datetime
|
||||
import csv
|
||||
import io
|
||||
from disp import FP_VAR
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@@ -15,20 +16,63 @@ init_db()
|
||||
@app.route('/')
|
||||
def index():
|
||||
finance_data = get_finance_data()
|
||||
depletion_date, savings_per_fortnight, final_savings, TLS, CBA = calculate_savings_depletion(finance_data)
|
||||
BUDGET=get_budget_data(finance_data, CBA, TLS)
|
||||
depletion_date, savings_per_fortnight, final_savings = calculate_savings_depletion(finance_data)
|
||||
BUDGET=get_budget_data(finance_data)
|
||||
|
||||
if depletion_date:
|
||||
depletion_date=depletion_date.date(); # just show date
|
||||
|
||||
# HARDCODED FOR NOW
|
||||
cset_id = 1
|
||||
# work out comparison func, but hardcode for now:
|
||||
COMP={}
|
||||
COMP['date'], COMP['amount'] = last_cset_savings_data( cset_id )
|
||||
COMP['vars']=finance_data
|
||||
COMP['savings_data']=savings_per_fortnight
|
||||
#HARDCODE HACK:
|
||||
finance_data['comp_set']=1
|
||||
|
||||
return render_template('index.html', finance=finance_data, depletion_date=depletion_date, savings=savings_per_fortnight, TLS=TLS, CBA=CBA, BUDGET=BUDGET, COMP=COMP)
|
||||
# we are comparing...
|
||||
if finance_data['comp_set'] >= 1:
|
||||
COMP=get_comp_set_data(finance_data['comp_set'])
|
||||
|
||||
DISP=[]
|
||||
# Row 1
|
||||
r=[]
|
||||
r.append( FP_VAR( 'D Salary', 'D_Salary' ) )
|
||||
r.append( FP_VAR( 'Savings', 'Savings' ) )
|
||||
r.append( FP_VAR( 'Car Loan via Pay', 'Car_loan_via_pay', 'readonly' ) )
|
||||
r.append( FP_VAR( 'Living Expenses', 'Living_Expenses' ) )
|
||||
r.append( FP_VAR( 'Overseas Trip', 'Overseas_trip', 'date', 'col-4', 'Overseas_trip_date' ) )
|
||||
DISP.append(r)
|
||||
|
||||
# Row 2
|
||||
r=[]
|
||||
r.append( FP_VAR( 'D # Fortnights pay', 'D_Num_fortnights_pay' ) )
|
||||
r.append( FP_VAR( 'Interest Rate', 'Interest_Rate' ) )
|
||||
r.append( FP_VAR( 'Car Loan', 'Car_loan', 'readonly' ) )
|
||||
r.append( FP_VAR( 'Inflation', 'Inflation' ) )
|
||||
r.append( FP_VAR( 'Reno Costs', 'Mark_reno', 'date', 'col-4', 'Mark_reno_date' ) )
|
||||
DISP.append(r)
|
||||
|
||||
# Row 2
|
||||
r=[]
|
||||
r.append( FP_VAR( 'D leave owed (in days)', 'D_leave_owed_in_days' ) )
|
||||
r.append( FP_VAR( 'M TLS amount', 'M_TLS_shares' ) )
|
||||
r.append( FP_VAR( 'Car Balloon', 'Car_balloon', 'readonly' ) )
|
||||
DISP.append(r)
|
||||
|
||||
# Row 3
|
||||
r=[]
|
||||
r.append( FP_VAR( 'D CBA amount', 'D_CBA_shares' ) )
|
||||
r.append( FP_VAR( 'D TLS amount', 'D_TLS_shares' ) )
|
||||
r.append( FP_VAR( 'Mich Present', 'Mich_present', 'readonly' ) )
|
||||
r.append( FP_VAR( 'Sell Shares for:', 'Sell_shares', 'select', 'offset-2 col-2' ) )
|
||||
DISP.append(r)
|
||||
|
||||
# Row 4
|
||||
r=[]
|
||||
r.append( FP_VAR( 'CBA price', 'CBA_price' ) )
|
||||
r.append( FP_VAR( 'TLS price', 'TLS_price' ) )
|
||||
r.append( FP_VAR( 'School Fees', 'School_Fees', 'readonly' ) )
|
||||
r.append( FP_VAR( 'FINAL # of CBA', 'CBA', 'readonly' ) )
|
||||
r.append( FP_VAR( 'FINAL # of TLS', 'TLS', 'readonly' ) )
|
||||
DISP.append(r)
|
||||
|
||||
return render_template('index.html', finance=finance_data, depletion_date=depletion_date, savings=savings_per_fortnight, BUDGET=BUDGET, COMP=COMP, DISP=DISP)
|
||||
|
||||
@app.route('/update', methods=['POST'])
|
||||
def update():
|
||||
@@ -67,7 +111,7 @@ def download_csv():
|
||||
|
||||
finance_data = get_finance_data()
|
||||
depletion_date, savings_per_fortnight, final_savings, TLS, CBA = calculate_savings_depletion(finance_data)
|
||||
BUDGET=get_budget_data(finance_data, CBA, TLS)
|
||||
BUDGET=get_budget_data(finance_data)
|
||||
|
||||
# Group data by year
|
||||
data_by_year = defaultdict(list)
|
||||
|
||||
Reference in New Issue
Block a user