From cc609ab56e4a061b7b34ddf7e692dc667d1b0647 Mon Sep 17 00:00:00 2001 From: Adarsh Murthy Date: Tue, 23 May 2017 11:37:15 -0400 Subject: [PATCH 1/8] Catch error properly for header component. --- .../static/financialInputs/scripts/app.js | 7 +++++-- blocnote/apps/financialInputs/views.py | 10 ++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js index fd36648..ff5bb51 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js @@ -151,7 +151,7 @@ function billProjectionDatesForm(form) { 'X-CSRFToken': Cookies.get('csrftoken') }) }).then(res => { - if (!res.payload.err) { + if (!res.err) { // Display response message. Add that loan options changed if fund was changed. Reset didFundChange to false. responseMessage = 'Saved'; if (didFundChange) { @@ -182,7 +182,10 @@ function billProjectionDatesForm(form) { else { // Display error message. var resMsg = document.querySelector('#pro-forma-form-save-msg'); - resMsg.innerHTML = `${res.payload.err}`; + res.err.responseBody.then((error) => { + resMsg.innerHTML = `${error.error}`; + console.log('Reason:',error.reason); + }) } }); } diff --git a/blocnote/apps/financialInputs/views.py b/blocnote/apps/financialInputs/views.py index 76770bd..3bf9d6b 100644 --- a/blocnote/apps/financialInputs/views.py +++ b/blocnote/apps/financialInputs/views.py @@ -148,8 +148,14 @@ class BlocNoteHeader(View): result = {} try: self.handle_form(put, building_id) - except: - result['err'] = 'Sorry, the data could not be saved.' + except Exception as err: + return JsonResponse( + { + 'error': 'Sorry, something went wrong. Please try again.', + 'reason': err, + }, + status=400 + ) return JsonResponse(result) def get(self, request, building_id): -- GitLab From d22bcc106e12e96ff6e067258e771dd2460587ed Mon Sep 17 00:00:00 2001 From: Adarsh Murthy Date: Tue, 23 May 2017 13:39:25 -0400 Subject: [PATCH 2/8] More status 400 JsonResponse returns. --- .../static/financialInputs/scripts/app.js | 31 +++-- .../templates/financialInputs/bills.html | 2 + blocnote/apps/financialInputs/views.py | 109 ++++++++++-------- 3 files changed, 85 insertions(+), 57 deletions(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js index ff5bb51..4ab47f2 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js @@ -184,7 +184,6 @@ function billProjectionDatesForm(form) { var resMsg = document.querySelector('#pro-forma-form-save-msg'); res.err.responseBody.then((error) => { resMsg.innerHTML = `${error.error}`; - console.log('Reason:',error.reason); }) } }); @@ -306,8 +305,20 @@ function sendFile(id, content) { 'X-CSRFToken': Cookies.get('csrftoken') }) }).then(res => { - var text = getText(res.payload.result, id); - updateTable(id, text); + if (!res.err) { + document.querySelector('#bills-warning-message').innerHTML = ` + ${id} bill upload success + `; + var text = getText(res.payload.result, id); + updateTable(id, text); + } + else { + res.err.responseBody.then((error) => { + document.querySelector('#bills-warning-message').innerHTML = ` + ${error.error} + `; + }) + } }); } @@ -479,7 +490,7 @@ function loadBillsOverview() { const table = document.querySelector('#Energy-Bills-Overview'); var text = ``; text += createEstimateModelForm(); - if (res.payload.instance.present) { + if (Object.keys(res.payload.instance).length !== 0) { text += createBillsOverviewTable(res.payload.instance); } table.innerHTML = text; @@ -507,8 +518,10 @@ function billsOverviewFormCalculate(data) { 'X-CSRFToken': Cookies.get('csrftoken') }) }).then(res => { - if (res.payload.instance['err']) { - alert(res.payload.instance['err']); + if (res.err) { + res.err.responseBody.then((error) => { + alert(error.error); + }) return false; } table = document.querySelector('#Energy-Bills-Overview') @@ -548,11 +561,13 @@ function billsOverviewFormSubmit(form) { }).then(res => { // Display error/success message. var message = ''; - if (!res.payload.err) { + if (!res.err) { message = 'Saved'; } else { - message = res.payload.err; + res.err.responseBody.then((error) => { + message = error.error; + }) } document.querySelector('#bills-overview-warning-message').innerHTML = ` ${message} diff --git a/blocnote/apps/financialInputs/templates/financialInputs/bills.html b/blocnote/apps/financialInputs/templates/financialInputs/bills.html index 5af7c79..ba93c5f 100644 --- a/blocnote/apps/financialInputs/templates/financialInputs/bills.html +++ b/blocnote/apps/financialInputs/templates/financialInputs/bills.html @@ -36,6 +36,8 @@ +
+
diff --git a/blocnote/apps/financialInputs/views.py b/blocnote/apps/financialInputs/views.py index 3bf9d6b..8d2b863 100644 --- a/blocnote/apps/financialInputs/views.py +++ b/blocnote/apps/financialInputs/views.py @@ -149,10 +149,10 @@ class BlocNoteHeader(View): try: self.handle_form(put, building_id) except Exception as err: + print(err) return JsonResponse( { 'error': 'Sorry, something went wrong. Please try again.', - 'reason': err, }, status=400 ) @@ -222,7 +222,10 @@ class BillsTable(View): rows to be displayed. """ put = json.loads(request.body.decode()) - result = self.handle_file(put, building_id) + try: + result = self.handle_file(put, building_id) + except ValueError as err: + return JsonResponse({'error': err.args[0] + 'Please make sure you uploaded the right file.'}, status=400) return JsonResponse({'result': result}) def handle_file(self, data, building_id): @@ -247,7 +250,10 @@ class BillsTable(View): ).delete() text = data['text'].split('\n') - + date_from_index = "" + date_to_index = "" + usage_index = "" + charge_index = "" column_headings = text[0].split(',') for index, heading in enumerate(column_headings): if heading == "Bill From Date": @@ -259,6 +265,15 @@ class BillsTable(View): elif "Total Charges" in heading: charge_index = index + if not date_from_index: + raise ValueError('Could not find "Bill From Date" column.') + if not date_to_index: + raise ValueError('Could not find "Bill To Date" column.') + if not usage_index: + raise ValueError('Could not find "Usage" column.') + if not charge_index: + raise ValueError('Could not find "Total Charge" column.') + result = [] for line in range(1, len(text)-1): row_list = [] @@ -299,24 +314,21 @@ class BillsTable(View): present = False utility_type = request.GET.get('utility_type') - try: - model_obj = self.model.objects.filter( - building_id=building_id, - utility_type=utility_type - ) - if model_obj: - present = True - for row in model_obj: - row_list = [] - row_list.append(row.date_from) - row_list.append(row.date_to) - row_list.append(row.usage) - row_list.append(row.charge) - result.append(row_list) - - return JsonResponse({'result': result, 'present': present}) - except: - return JsonResponse({'result': result, 'present': present}) + model_obj = self.model.objects.filter( + building_id=building_id, + utility_type=utility_type + ) + if model_obj: + present = True + for row in model_obj: + row_list = [] + row_list.append(row.date_from) + row_list.append(row.date_to) + row_list.append(row.usage) + row_list.append(row.charge) + result.append(row_list) + + return JsonResponse({'result': result, 'present': present}) def get_total_charge(utility_type, analysis_date, building_id): @@ -445,30 +457,30 @@ class BillsOverviewView(View): result = {} total_annual_charge = [] if objs: - result['present'] = True - else: - result['present'] = False - result['electricity'] = {} - result['gas'] = {} - result['oil'] = {} - result['water'] = {} - result['electricity_user'] = True - result['gas_user'] = True - result['oil_user'] = True - result['water_user'] = True - for obj in objs: - store_year = str(obj.year) - result['electricity'][store_year] = float("{0:.2f}".format(obj.electricity)) - result['gas'][store_year] = float("{0:.2f}".format(obj.gas)) - result['oil'][store_year] = float("{0:.2f}".format(obj.oil)) - result['water'][store_year] = float("{0:.2f}".format(obj.water)) - result['electricity_user'] = obj.electricity_is_user_input - result['gas_user'] = obj.gas_is_user_input - result['oil_user'] = obj.oil_is_user_input - result['water_user'] = obj.water_is_user_input - total_annual_charge.append(obj.electricity + obj.gas + obj.oil + obj.water) - result['total_annual_charge'] = total_annual_charge - + result['electricity'] = {} + result['gas'] = {} + result['oil'] = {} + result['water'] = {} + result['electricity_user'] = True + result['gas_user'] = True + result['oil_user'] = True + result['water_user'] = True + for obj in objs: + store_year = str(obj.year) + result['electricity'][store_year] = float("{0:.2f}".format(obj.electricity)) if obj.electricity else None + result['gas'][store_year] = float("{0:.2f}".format(obj.gas)) if obj.gas else None + result['oil'][store_year] = float("{0:.2f}".format(obj.oil)) if obj.oil else None + result['water'][store_year] = float("{0:.2f}".format(obj.water)) if obj.water else None + result['electricity_user'] = obj.electricity_is_user_input + result['gas_user'] = obj.gas_is_user_input + result['oil_user'] = obj.oil_is_user_input + result['water_user'] = obj.water_is_user_input + total = 0 + for util in self.utility: + if result[util][store_year]: + total += result[util][store_year] + total_annual_charge.append(total) + result['total_annual_charge'] = total_annual_charge return JsonResponse({'instance': result}) def put(self, request, building_id): @@ -499,8 +511,7 @@ class BillsOverviewView(View): projected_bills = {} pro_forma_object = get_model_object(FinancingOverview, building_id) if not pro_forma_object: - projected_bills['err'] = 'Please fill in bill projection date, period and funds form' - return JsonResponse({'instance': projected_bills}) + return JsonResponse({'error': 'Please fill in bill projection date, period and funds form'}, status=400) analysis_date = get_analysis_date(building_id) if put['Estimation Model'] == 'Rough Estimation': for util in self.utility: @@ -521,7 +532,7 @@ class BillsOverviewView(View): total_annual_charge.append(total) projected_bills['total_annual_charge'] = total_annual_charge else: - projected_bills['err'] = 'Only Rough Estimation available at this point' + return JsonResponse({'error': 'Only Rough Estimation available at this point'}, status=400) return JsonResponse({'instance': projected_bills}) def post(self, request, building_id): @@ -561,7 +572,7 @@ class BillsOverviewView(View): water_is_user_input=w_user ) except: - return JsonResponse({'err': 'Could not save table!'}) + return JsonResponse({'error': 'Could not save table!'}, status=400) return JsonResponse({}) -- GitLab From 76d7eb70ce455cf02e11cd3135b200ef2b22a5ff Mon Sep 17 00:00:00 2001 From: Adarsh Murthy Date: Tue, 23 May 2017 13:58:52 -0400 Subject: [PATCH 3/8] Undo bills overview changes from this PR. --- .../static/financialInputs/scripts/app.js | 12 ++++------- blocnote/apps/financialInputs/views.py | 20 ++++++++----------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js index 4ab47f2..f118f4c 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js @@ -518,10 +518,8 @@ function billsOverviewFormCalculate(data) { 'X-CSRFToken': Cookies.get('csrftoken') }) }).then(res => { - if (res.err) { - res.err.responseBody.then((error) => { - alert(error.error); - }) + if (res.payload.err) { + alert(res.payload.err); return false; } table = document.querySelector('#Energy-Bills-Overview') @@ -561,13 +559,11 @@ function billsOverviewFormSubmit(form) { }).then(res => { // Display error/success message. var message = ''; - if (!res.err) { + if (!res.payload.err) { message = 'Saved'; } else { - res.err.responseBody.then((error) => { - message = error.error; - }) + message = res.payload.err; } document.querySelector('#bills-overview-warning-message').innerHTML = ` ${message} diff --git a/blocnote/apps/financialInputs/views.py b/blocnote/apps/financialInputs/views.py index 8d2b863..c63a226 100644 --- a/blocnote/apps/financialInputs/views.py +++ b/blocnote/apps/financialInputs/views.py @@ -467,19 +467,15 @@ class BillsOverviewView(View): result['water_user'] = True for obj in objs: store_year = str(obj.year) - result['electricity'][store_year] = float("{0:.2f}".format(obj.electricity)) if obj.electricity else None - result['gas'][store_year] = float("{0:.2f}".format(obj.gas)) if obj.gas else None - result['oil'][store_year] = float("{0:.2f}".format(obj.oil)) if obj.oil else None - result['water'][store_year] = float("{0:.2f}".format(obj.water)) if obj.water else None + result['electricity'][store_year] = float("{0:.2f}".format(obj.electricity)) + result['gas'][store_year] = float("{0:.2f}".format(obj.gas)) + result['oil'][store_year] = float("{0:.2f}".format(obj.oil)) + result['water'][store_year] = float("{0:.2f}".format(obj.water)) result['electricity_user'] = obj.electricity_is_user_input result['gas_user'] = obj.gas_is_user_input result['oil_user'] = obj.oil_is_user_input result['water_user'] = obj.water_is_user_input - total = 0 - for util in self.utility: - if result[util][store_year]: - total += result[util][store_year] - total_annual_charge.append(total) + total_annual_charge.append(obj.electricity + obj.gas + obj.oil + obj.water) result['total_annual_charge'] = total_annual_charge return JsonResponse({'instance': result}) @@ -511,7 +507,7 @@ class BillsOverviewView(View): projected_bills = {} pro_forma_object = get_model_object(FinancingOverview, building_id) if not pro_forma_object: - return JsonResponse({'error': 'Please fill in bill projection date, period and funds form'}, status=400) + return JsonResponse({'err': 'Please fill in bill projection date, period and funds form'}) analysis_date = get_analysis_date(building_id) if put['Estimation Model'] == 'Rough Estimation': for util in self.utility: @@ -532,7 +528,7 @@ class BillsOverviewView(View): total_annual_charge.append(total) projected_bills['total_annual_charge'] = total_annual_charge else: - return JsonResponse({'error': 'Only Rough Estimation available at this point'}, status=400) + return JsonResponse({'err': 'Only Rough Estimation available at this point'}) return JsonResponse({'instance': projected_bills}) def post(self, request, building_id): @@ -572,7 +568,7 @@ class BillsOverviewView(View): water_is_user_input=w_user ) except: - return JsonResponse({'error': 'Could not save table!'}, status=400) + return JsonResponse({'err': 'Could not save table!'}) return JsonResponse({}) -- GitLab From 374e491e1b4c1c0284937c1039772754c78c27f8 Mon Sep 17 00:00:00 2001 From: Adarsh Murthy Date: Tue, 30 May 2017 15:02:57 -0400 Subject: [PATCH 4/8] Indentation changes. --- blocnote/apps/financialInputs/views.py | 28 +++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/blocnote/apps/financialInputs/views.py b/blocnote/apps/financialInputs/views.py index 9f9b1d6..483073f 100644 --- a/blocnote/apps/financialInputs/views.py +++ b/blocnote/apps/financialInputs/views.py @@ -443,20 +443,20 @@ class BillsOverviewView(View): for obj in objs: store_year = str(obj.year) # Limit number of decimal places only if a value exists else keep it as None. - result['electricity'][store_year] = (float("{0:.2f}".format(obj.electricity)) if obj.electricity else None) - result['gas'][store_year] = (float("{0:.2f}".format(obj.gas)) if obj.gas else None) - result['oil'][store_year] = (float("{0:.2f}".format(obj.oil)) if obj.oil else None) - result['water'][store_year] = (float("{0:.2f}".format(obj.water)) if obj.water else None) - result['electricity_user'] = obj.electricity_is_user_input - result['gas_user'] = obj.gas_is_user_input - result['oil_user'] = obj.oil_is_user_input - result['water_user'] = obj.water_is_user_input - # Calculate total charge for a year. Consider None as 0 for this purpose. - total = 0 - for util in self.utility: - if result[util][store_year]: - total += result[util][store_year] - total_annual_charge.append(total) + result['electricity'][store_year] = (float("{0:.2f}".format(obj.electricity)) if obj.electricity else None) + result['gas'][store_year] = (float("{0:.2f}".format(obj.gas)) if obj.gas else None) + result['oil'][store_year] = (float("{0:.2f}".format(obj.oil)) if obj.oil else None) + result['water'][store_year] = (float("{0:.2f}".format(obj.water)) if obj.water else None) + result['electricity_user'] = obj.electricity_is_user_input + result['gas_user'] = obj.gas_is_user_input + result['oil_user'] = obj.oil_is_user_input + result['water_user'] = obj.water_is_user_input + # Calculate total charge for a year. Consider None as 0 for this purpose. + total = 0 + for util in self.utility: + if result[util][store_year]: + total += result[util][store_year] + total_annual_charge.append(total) result['total_annual_charge'] = total_annual_charge return JsonResponse({'instance': result}) -- GitLab From 26257561dfd43fd8e6846b97274b9886a03244d6 Mon Sep 17 00:00:00 2001 From: Adarsh Murthy Date: Tue, 30 May 2017 15:27:04 -0400 Subject: [PATCH 5/8] Some minor edits adding status 400 to error messages. --- .../static/financialInputs/scripts/app.js | 12 ++++++++---- blocnote/apps/financialInputs/views.py | 6 +++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js index e5b4457..67a9c36 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js @@ -522,8 +522,10 @@ function billsOverviewFormCalculate(data) { 'X-CSRFToken': Cookies.get('csrftoken') }) }).then(res => { - if (res.payload.err) { - alert(res.payload.err); + if (res.err) { + res.err.responseBody.then((error) => { + alert(error.error); + }) return false; } table = document.querySelector('#Energy-Bills-Overview') @@ -563,11 +565,13 @@ function billsOverviewFormSubmit(form) { }).then(res => { // Display error/success message. var message = ''; - if (!res.payload.err) { + if (!res.err) { message = 'Saved'; } else { - message = res.payload.err; + res.err.responseBody.then((error) => { + message = res.payload.err; + }); } document.querySelector('#bills-overview-warning-message').innerHTML = ` ${message} diff --git a/blocnote/apps/financialInputs/views.py b/blocnote/apps/financialInputs/views.py index 483073f..fbedfca 100644 --- a/blocnote/apps/financialInputs/views.py +++ b/blocnote/apps/financialInputs/views.py @@ -488,7 +488,7 @@ class BillsOverviewView(View): projected_bills = {} pro_forma_object = get_model_object(FinancingOverview, building_id) if not pro_forma_object: - return JsonResponse({'err': 'Please fill in bill projection date, period and funds form'}) + return JsonResponse({'error': 'Please fill in bill projection date, period and funds form'}, status=400) analysis_date = get_analysis_date(building_id) if put['Estimation Model'] == 'Rough Estimation': # Fetch all bills from the database. @@ -549,7 +549,7 @@ class BillsOverviewView(View): total_annual_charge.append(total) projected_bills['total_annual_charge'] = total_annual_charge else: - return JsonResponse({'err': 'Only Rough Estimation available at this point'}) + return JsonResponse({'error': 'Only Rough Estimation available at this point'}, status=400) return JsonResponse({'instance': projected_bills}) def post(self, request, building_id): @@ -594,7 +594,7 @@ class BillsOverviewView(View): water_is_user_input=w_user ) except: - return JsonResponse({'err': 'Could not save table!'}) + return JsonResponse({'error': 'Could not save table!'}, status=400) return JsonResponse({}) -- GitLab From 944d93ac4c7ad26a92891abd66011c02a703765a Mon Sep 17 00:00:00 2001 From: Adarsh Murthy Date: Wed, 31 May 2017 14:51:17 -0400 Subject: [PATCH 6/8] Minor edits in coding style. --- .../financialInputs/static/financialInputs/scripts/app.js | 2 +- blocnote/apps/financialInputs/views.py | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js index 67a9c36..5fa9a06 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js @@ -308,7 +308,7 @@ function sendFile(id, content) { if (!res.err) { document.querySelector('#bills-warning-message').innerHTML = ` ${id} bill upload success - `; + `; var text = getText(res.payload.result, id); updateTable(id, text); } diff --git a/blocnote/apps/financialInputs/views.py b/blocnote/apps/financialInputs/views.py index fbedfca..1d1a050 100644 --- a/blocnote/apps/financialInputs/views.py +++ b/blocnote/apps/financialInputs/views.py @@ -188,13 +188,10 @@ class BlocNoteHeader(View): try: self.handle_form(put, building_id) except Exception as err: - print(err) return JsonResponse( { 'error': 'Sorry, something went wrong. Please try again.', - }, - status=400 - ) + }, status=400) return JsonResponse(result) def get(self, request, building_id): @@ -356,7 +353,7 @@ class BillsTable(View): model_obj = self.model.objects.filter( building_id=building_id, utility_type=utility_type - ) + ) if model_obj: present = True for row in model_obj: -- GitLab From 476b3e587f09d5db6d7f0013778ad38268bf8c8a Mon Sep 17 00:00:00 2001 From: Adarsh Murthy Date: Wed, 31 May 2017 16:44:41 -0400 Subject: [PATCH 7/8] Remove indentation. --- blocnote/apps/financialInputs/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blocnote/apps/financialInputs/views.py b/blocnote/apps/financialInputs/views.py index 1d1a050..e4de173 100644 --- a/blocnote/apps/financialInputs/views.py +++ b/blocnote/apps/financialInputs/views.py @@ -454,7 +454,7 @@ class BillsOverviewView(View): if result[util][store_year]: total += result[util][store_year] total_annual_charge.append(total) - result['total_annual_charge'] = total_annual_charge + result['total_annual_charge'] = total_annual_charge return JsonResponse({'instance': result}) def put(self, request, building_id): -- GitLab From 2906b6811d5fb41e1e15950cc495ee97ce12ef8e Mon Sep 17 00:00:00 2001 From: Adarsh Murthy Date: Wed, 31 May 2017 17:20:39 -0400 Subject: [PATCH 8/8] Changed id of response message div for bills. Changes the implementation of the utility user input boolean. --- .../templates/financialInputs/bills.html | 2 +- blocnote/apps/financialInputs/views.py | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/blocnote/apps/financialInputs/templates/financialInputs/bills.html b/blocnote/apps/financialInputs/templates/financialInputs/bills.html index ba93c5f..98cc36e 100644 --- a/blocnote/apps/financialInputs/templates/financialInputs/bills.html +++ b/blocnote/apps/financialInputs/templates/financialInputs/bills.html @@ -36,7 +36,7 @@ -
+
diff --git a/blocnote/apps/financialInputs/views.py b/blocnote/apps/financialInputs/views.py index e4de173..35d0b4f 100644 --- a/blocnote/apps/financialInputs/views.py +++ b/blocnote/apps/financialInputs/views.py @@ -428,15 +428,16 @@ class BillsOverviewView(View): objs = self.model_bills_overview.objects.filter(building_id=building_id) result = {} total_annual_charge = [] + electricity_user, gas_user, oil_user, water_user = get_if_user_input(building_id) if objs: result['electricity'] = {} result['gas'] = {} result['oil'] = {} result['water'] = {} - result['electricity_user'] = True - result['gas_user'] = True - result['oil_user'] = True - result['water_user'] = True + result['electricity_user'] = electricity_user + result['gas_user'] = gas_user + result['oil_user'] = oil_user + result['water_user'] = water_user for obj in objs: store_year = str(obj.year) # Limit number of decimal places only if a value exists else keep it as None. @@ -444,10 +445,6 @@ class BillsOverviewView(View): result['gas'][store_year] = (float("{0:.2f}".format(obj.gas)) if obj.gas else None) result['oil'][store_year] = (float("{0:.2f}".format(obj.oil)) if obj.oil else None) result['water'][store_year] = (float("{0:.2f}".format(obj.water)) if obj.water else None) - result['electricity_user'] = obj.electricity_is_user_input - result['gas_user'] = obj.gas_is_user_input - result['oil_user'] = obj.oil_is_user_input - result['water_user'] = obj.water_is_user_input # Calculate total charge for a year. Consider None as 0 for this purpose. total = 0 for util in self.utility: -- GitLab