diff --git a/README b/README index 515b94b..03883f6 100644 --- a/README +++ b/README @@ -1,8 +1,4 @@ TODO: - * make save button create a comparison set to use - (also consider how to clean / re-create db initial values from code -- easily could just drop/recreate per table, and only drop finance, not csets) - * then delete export button - CONSIDER in code: * when we time the payment of GMHBA / HCF (and at what cadence) and include it in calcs better diff --git a/db.py b/db.py index 51ec6dd..7802f47 100644 --- a/db.py +++ b/db.py @@ -149,6 +149,7 @@ def update_finance(data): def insert_cset( data ): + print( f"Saving: {data['vars']['name']}" ) conn = connect_db(False) cur = conn.cursor() cur.execute('''INSERT INTO comparison_set ( diff --git a/main.py b/main.py index 99ddceb..0656ccb 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,7 @@ # main.py -from flask import Flask, render_template, request, redirect, url_for, Response +from flask import Flask, render_template, request, redirect, url_for, Response, jsonify from calc import calculate_savings_depletion -from db import init_db, get_finance_data, update_finance, get_budget_data, get_comp_set_data, get_comp_set_options +from db import init_db, get_finance_data, update_finance, get_budget_data, insert_cset, get_comp_set_data, get_comp_set_options from collections import defaultdict from datetime import datetime import csv @@ -10,6 +10,9 @@ from disp import FP_VAR app = Flask(__name__) +# core vars that we will save for comparisons +VARS= ( 'D_Salary', 'D_Num_fortnights_pay', 'School_Fees', 'Car_loan_via_pay', 'Car_loan', 'Car_balloon', 'Living_Expenses', 'Savings', 'Interest_Rate', 'Inflation', 'Mich_present', 'Overseas_trip', 'Mark_reno', 'D_leave_owed_in_days', 'D_TLS_shares', 'M_TLS_shares', 'D_CBA_shares', 'TLS_price', 'CBA_price', 'Overseas_trip_date', 'Mark_reno_date', 'Sell_shares', 'CBA', 'TLS' ) + # Initialize the database init_db() @@ -74,8 +77,7 @@ def index(): @app.route('/save', methods=['POST']) def save(): - for el in request.form: - print(f"SAVE: {el}={request.form[el]}") + insert_cset( request.get_json() ) return "200" @app.route('/update', methods=['POST']) diff --git a/templates/index.html b/templates/index.html index 14348e0..a010063 100644 --- a/templates/index.html +++ b/templates/index.html @@ -284,7 +284,8 @@ $.ajax( { type: 'POST', url: '/save', - data: { 'vars': vars, 'savings_data' :savingsData }, + contentType: 'application/json', + data: JSON.stringify( { 'vars': vars, 'savings_data' :savingsData } ), success: function() { $('#save_modal').modal('hide'); } } )" >Save