From 211fd6461e83a1bf194ed4714c0c0e83a5f1ddf5 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Mon, 26 Jun 2017 11:04:51 -0400 Subject: [PATCH 01/20] Move liabilities code to new liabilities file. --- .../apps/financialInputs/views/liabilities.py | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 blocnote/apps/financialInputs/views/liabilities.py diff --git a/blocnote/apps/financialInputs/views/liabilities.py b/blocnote/apps/financialInputs/views/liabilities.py new file mode 100644 index 0000000..b4df0bb --- /dev/null +++ b/blocnote/apps/financialInputs/views/liabilities.py @@ -0,0 +1,63 @@ +"""Views for liabilities.""" +import json + +from django.views import View +from django.http import JsonResponse + +from blocnote.apps.financialInputs.models import Liabilities + +class LiabilitiesTable(View): + """Store and load Mortgage and Liability information for a building id.""" + + model = Liabilities + + def get(self, request, building_id): + """HTTP GET request. + + Fetch Mortgage and Liability information from the database and return to the frontend. + + Args: + request: HTTP GET request. + building_id: id of the building. + + Returns: + JsonResponse: List of records. Each record is a dictionary with key as the attribute name and value + as the value. + """ + objs = self.model.objects.filter(building_id=building_id) + result = [] + if objs: + for obj in objs: + record = { + 'lender': obj.lender, + 'input_date': obj.input_date, + 'monthly_service': obj.monthly_service, + 'remaining_term': obj.remaining_term, + } + result.append(record) + return JsonResponse({'instance': result}) + + def put(self, request, building_id): + """HTTP PUT request. + + Receive Mortgage and Liabilities data from frontend and store in the database. Delete any existing records + before storing new data. + + Args: + request: HTTP PUT request. + building_id: id of the building. + + Returns: + JsonResponse: A status saying OK. + """ + put = json.loads(request.body.decode()) + self.model.objects.filter(building_id=building_id).delete() + for record in put: + self.model.objects.create( + building_id=building_id, + input_date=record['input_date'], + lender=record['lender'], + monthly_service=float(record['monthly-service']), + remaining_term=float(record['remaining-term']), + ) + return JsonResponse({}) -- GitLab From 6d9fe73a5a5d1ef44bbcd20d2cd7292e345c5844 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Mon, 26 Jun 2017 11:17:54 -0400 Subject: [PATCH 02/20] Change code in liabilities to be update or create instead of delete and then create. --- blocnote/apps/financialInputs/views/liabilities.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/blocnote/apps/financialInputs/views/liabilities.py b/blocnote/apps/financialInputs/views/liabilities.py index b4df0bb..54b84e7 100644 --- a/blocnote/apps/financialInputs/views/liabilities.py +++ b/blocnote/apps/financialInputs/views/liabilities.py @@ -53,6 +53,11 @@ class LiabilitiesTable(View): put = json.loads(request.body.decode()) self.model.objects.filter(building_id=building_id).delete() for record in put: + record['building_id'] = building_id + self.model.objects.update_or_create( + building_id=building_id, + defaults=record, + ) self.model.objects.create( building_id=building_id, input_date=record['input_date'], -- GitLab From 46ccebd29d6bd778bb1ffbe8d0050817108c1ae8 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Mon, 26 Jun 2017 11:22:46 -0400 Subject: [PATCH 03/20] Change code in liabilities to be update or create instead of delete and then create. --- blocnote/apps/financialInputs/views/liabilities.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/blocnote/apps/financialInputs/views/liabilities.py b/blocnote/apps/financialInputs/views/liabilities.py index 54b84e7..123b162 100644 --- a/blocnote/apps/financialInputs/views/liabilities.py +++ b/blocnote/apps/financialInputs/views/liabilities.py @@ -51,18 +51,10 @@ class LiabilitiesTable(View): JsonResponse: A status saying OK. """ put = json.loads(request.body.decode()) - self.model.objects.filter(building_id=building_id).delete() for record in put: record['building_id'] = building_id self.model.objects.update_or_create( building_id=building_id, defaults=record, ) - self.model.objects.create( - building_id=building_id, - input_date=record['input_date'], - lender=record['lender'], - monthly_service=float(record['monthly-service']), - remaining_term=float(record['remaining-term']), - ) return JsonResponse({}) -- GitLab From d58c0d6e64388d072f80e7de5bdbfa9da8c55027 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Mon, 26 Jun 2017 14:33:58 -0400 Subject: [PATCH 04/20] Create a new form for liaiblities. --- blocnote/apps/financialInputs/forms.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/blocnote/apps/financialInputs/forms.py b/blocnote/apps/financialInputs/forms.py index ce532fc..8324924 100644 --- a/blocnote/apps/financialInputs/forms.py +++ b/blocnote/apps/financialInputs/forms.py @@ -1,6 +1,6 @@ """Forms to render and validate for financial-inputs endpoint.""" from django.forms import ModelForm -from blocnote.apps.financialInputs.models import FinancingOverview, CustomerPreference +from blocnote.apps.financialInputs.models import FinancingOverview, CustomerPreference, Liabilities class ProformaInputsForm(ModelForm): @@ -33,3 +33,11 @@ class CustomerPreferenceForm(ModelForm): 'expected_payback', 'expected_net_noi_dscr', ] + + +class Liabilitiesform(ModelForm): + """Define the form that validates the liabilities records of the customer.""" + + class Meta: + model = Liabilities + fields = '__all__' -- GitLab From 9cb602cbecd9152639adf7687683e5ed7dd1c998 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Mon, 26 Jun 2017 15:30:52 -0400 Subject: [PATCH 05/20] Remove liabilities cide from old views . --- blocnote/apps/financialInputs/old_views.py | 57 ---------------------- 1 file changed, 57 deletions(-) diff --git a/blocnote/apps/financialInputs/old_views.py b/blocnote/apps/financialInputs/old_views.py index f3d9210..206299e 100644 --- a/blocnote/apps/financialInputs/old_views.py +++ b/blocnote/apps/financialInputs/old_views.py @@ -487,63 +487,6 @@ class BillsOverviewView(View): return JsonResponse({}) -class LiabilitiesTable(View): - """Store and load Mortgage and Liability information for a building id.""" - - model = Liabilities - - def get(self, request, building_id): - """HTTP GET request. - - Fetch Mortgage and Liability information from the database and return to the frontend. - - Args: - request: HTTP GET request. - building_id: id of the building. - - Returns: - JsonResponse: List of records. Each record is a dictionary with key as the attribute name and value - as the value. - """ - objs = self.model.objects.filter(building_id=building_id) - result = [] - if objs: - for obj in objs: - record = { - 'lender': obj.lender, - 'input_date': obj.input_date, - 'monthly_service': obj.monthly_service, - 'remaining_term': obj.remaining_term, - } - result.append(record) - return JsonResponse({'instance': result}) - - def put(self, request, building_id): - """HTTP PUT request. - - Receive Mortgage and Liabilities data from frontend and store in the database. Delete any existing records - before storing new data. - - Args: - request: HTTP PUT request. - building_id: id of the building. - - Returns: - JsonResponse: A status saying OK. - """ - put = json.loads(request.body.decode()) - self.model.objects.filter(building_id=building_id).delete() - for record in put: - self.model.objects.create( - building_id=building_id, - input_date=record['input_date'], - lender=record['lender'], - monthly_service=float(record['monthly-service']), - remaining_term=float(record['remaining-term']), - ) - return JsonResponse({}) - - class CashBalanceView(View): """Display, store and use cash balance data.""" -- GitLab From 55fd699d09746189c5de2ee01ca5b55dce2c0375 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Mon, 26 Jun 2017 15:57:48 -0400 Subject: [PATCH 06/20] Add js code to new liabilities file. --- .../financialInputs/scripts/liabilities.js | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js new file mode 100644 index 0000000..b75c59f --- /dev/null +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js @@ -0,0 +1,127 @@ +/** + * Load the Mortgage and Liabilities table. + * This function loads the mortgage and liabilities table with the given inputList. If inputList is empty, it loads a + * row with empty inputs and 1/1/1980 date as default values. + */ +function loadLiabilitiesTable(inputList) { + if (inputList.length === 0) { + addLiabilitiesRow('', '', '', ''); + } + else { + inputList.map(function(record, index) { + record = inputList[index]; + let lender = record['lender']; + let service = record['monthly_service']; + let term = record['remaining_term']; + let date = record['input_date']; + addLiabilitiesRow(lender, service, term, date); + }); + } +} + +/**Add a new row to Mortgage and Liabilities table. */ +function addLiabilitiesRow(lender, service, term, date) { + const table = document.querySelector('#liabilities-table tbody'); + let rowCount = table.rows.length; + let row = table.insertRow(rowCount); + let cell = row.insertCell(0); + cell.innerHTML = `Debt ${rowCount + 1}`; + cell = row.insertCell(1); + cell.innerHTML = ` + + `; + cell = row.insertCell(2); + cell.innerHTML = ` + + `; + cell = row.insertCell(3); + cell.innerHTML = ` + + `; + cell = row.insertCell(4); + cell.innerHTML = ` + + `; + cell = row.insertCell(5); + cell.innerHTML = ` +
+ +
+ `; +} + +/**Delete a row from the Mortgage and Liabilities table. */ +function deleteLiabilitiesRow(rowIndex) { + const result = confirm('ARE YOU SURE YOU WANT TO DELETE THIS ROW?'); + if (result) { + const table = document.querySelector('#liabilities-table'); + table.deleteRow(rowIndex); + const rowCount = table.rows.length; + for (let rowInd = 1; rowInd < rowCount; rowInd++) { + let row = table.rows.item(rowInd).cells; + row.item(0).innerHTML = `Debt ${rowInd}`; + } + } + return false; +} + +const liabilitiesForm = document.querySelector('#Liabilities'); +liabilitiesForm.onchange = function() { + document.querySelector('#liabilities-warning-message').innerHTML = ''; +}; + +/**HTTP PUT request with the user inputs for Mortgage and Liability. */ +function liabilitiesSubmitForm(form) { + const table = document.querySelector('#liabilities-table'); + const rowCount = table.rows.length; + let result = []; + for (let rowInd = 1; rowInd < rowCount; rowInd++) { + let record = {}; + record['lender'] = table.rows[rowInd].cells[1].children[0].value; + record['monthly-service'] = table.rows[rowInd].cells[2].children[0].value; + record['remaining-term'] = table.rows[rowInd].cells[3].children[0].value; + let date = table.rows[rowInd].cells[4].children[0].value; + let dateSplit = date.split('-'); + const dateDict = { + 'day': Number(dateSplit[2]), + 'month': Number(dateSplit[1]), + 'year': Number(dateSplit[0]), + }; + if (!validateDate(dateDict, todaysDate)) { + alert('Input Date cannot be in the future'); + return false; + } + record['input_date'] = date; + result.push(record); + } + request('liabilities/', { + method: 'PUT', + credentials: 'same-origin', + body: JSON.stringify(result), + headers: new Headers({ + 'Content-Type': 'application/json', + 'X-CSRFToken': Cookies.get('csrftoken') + }) + }).then(res => { + if (!res.payload.err) { + document.querySelector('#liabilities-warning-message').innerHTML = ` + Saved! + `; + } + }); + return false; +} + +/**HTTP GET request for any Mortgage and Liability data for the building id. */ +function getLiabilitiesTable() { + request('liabilities/', { + method: 'GET', + credentials: 'same-origin', + headers: { + 'Content-Type': 'application/json' + }, + }).then(res => { + loadLiabilitiesTable(res.payload.instance); + }); +} + -- GitLab From 34711d5df7179d730401e7ae041c7297129e8c81 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Mon, 26 Jun 2017 16:15:54 -0400 Subject: [PATCH 07/20] Remove liabilities code from app js. --- .../static/financialInputs/scripts/app.js | 128 ------------------ 1 file changed, 128 deletions(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js index 416d0b5..ad2dcb1 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js @@ -417,134 +417,6 @@ function billsOverviewFormSubmit(form) { return false; } -/** - * Load the Mortgage and Liabilities table. - * This function loads the mortgage and liabilities table with the given inputList. If inputList is empty, it loads a - * row with empty inputs and 1/1/1980 date as default values. - */ -function loadLiabilitiesTable(inputList) { - table = document.querySelector('#liabilities-table'); - if (inputList.length === 0) { - addLiabilitiesRow('', '', '', ''); - } - else { - inputList.map(function(record, index) { - record = inputList[index]; - lender = record['lender']; - service = record['monthly_service']; - term = record['remaining_term']; - date = record['input_date']; - addLiabilitiesRow(lender, service, term, date); - }); - } -} - -/**Add a new row to Mortgage and Liabilities table. */ -function addLiabilitiesRow(lender, service, term, date) { - table = document.querySelector('#liabilities-table tbody'); - var rowCount = table.rows.length; - var row = table.insertRow(rowCount); - var cell = row.insertCell(0); - cell.innerHTML = `Debt ${rowCount + 1}`; - cell = row.insertCell(1); - cell.innerHTML = ` - - `; - cell = row.insertCell(2); - cell.innerHTML = ` - - `; - cell = row.insertCell(3); - cell.innerHTML = ` - - `; - cell = row.insertCell(4); - cell.innerHTML = ` - - `; - cell = row.insertCell(5); - cell.innerHTML = ` -
- -
- `; -} - -/**Delete a row from the Mortgage and Liabilities table. */ -function deleteLiabilitiesRow(rowIndex) { - var result = confirm("ARE YOU SURE YOU WANT TO DELETE THIS ROW?"); - if (result) { - table = document.querySelector('#liabilities-table'); - table.deleteRow(rowIndex); - var rowCount = table.rows.length; - for (var rowInd = 1; rowInd < rowCount; rowInd++) { - row = table.rows.item(rowInd).cells; - row.item(0).innerHTML = `Debt ${rowInd}`; - } - } - return false; -} - -var liabilitiesForm = document.querySelector('#Liabilities'); -liabilitiesForm.onchange = function() { - document.querySelector('#liabilities-warning-message').innerHTML = ''; -} - -/**HTTP PUT request with the user inputs for Mortgage and Liability. */ -function liabilitiesSubmitForm(form) { - table = document.querySelector('#liabilities-table'); - var rowCount = table.rows.length; - var result = []; - for (rowInd = 1; rowInd < rowCount; rowInd++) { - record = {}; - record['lender'] = table.rows[rowInd].cells[1].children[0].value; - record['monthly-service'] = table.rows[rowInd].cells[2].children[0].value; - record['remaining-term'] = table.rows[rowInd].cells[3].children[0].value; - date = table.rows[rowInd].cells[4].children[0].value; - dateSplit = date.split('-'); - dateDict = { - 'day': Number(dateSplit[2]), - 'month': Number(dateSplit[1]), - 'year': Number(dateSplit[0]), - } - if (!validateDate(dateDict, todaysDate)) { - alert('Input Date cannot be in the future'); - return false; - } - record['input_date'] = date; - result.push(record); - } - request('liabilities/', { - method: 'PUT', - credentials: 'same-origin', - body: JSON.stringify(result), - headers: new Headers({ - 'Content-Type': 'application/json', - 'X-CSRFToken': Cookies.get('csrftoken') - }) - }).then(res => { - if (!res.payload.err) { - document.querySelector('#liabilities-warning-message').innerHTML = ` - Saved! - `; - } - }); - return false; -} - -/**HTTP GET request for any Mortgage and Liability data for the building id. */ -function getLiabilitiesTable() { - request(`liabilities/`, { - method: 'GET', - credentials: 'same-origin', - headers: { - 'Content-Type': 'application/json' - }, - }).then(res => { - loadLiabilitiesTable(res.payload.instance); - }); -} - /**Send HTTP GET request to obtain all cash balance records. */ function getCashBalanceForm() { request(`cash-balance/`, { -- GitLab From 0f36a333752637d8a97c749dcffeb23caf7c6237 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Mon, 26 Jun 2017 16:16:20 -0400 Subject: [PATCH 08/20] Update code to use js Date object. --- .../static/financialInputs/scripts/liabilities.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js index b75c59f..46eb611 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js @@ -22,7 +22,7 @@ function loadLiabilitiesTable(inputList) { /**Add a new row to Mortgage and Liabilities table. */ function addLiabilitiesRow(lender, service, term, date) { const table = document.querySelector('#liabilities-table tbody'); - let rowCount = table.rows.length; + const rowCount = table.rows.length; let row = table.insertRow(rowCount); let cell = row.insertCell(0); cell.innerHTML = `Debt ${rowCount + 1}`; @@ -81,13 +81,9 @@ function liabilitiesSubmitForm(form) { record['monthly-service'] = table.rows[rowInd].cells[2].children[0].value; record['remaining-term'] = table.rows[rowInd].cells[3].children[0].value; let date = table.rows[rowInd].cells[4].children[0].value; - let dateSplit = date.split('-'); - const dateDict = { - 'day': Number(dateSplit[2]), - 'month': Number(dateSplit[1]), - 'year': Number(dateSplit[0]), - }; - if (!validateDate(dateDict, todaysDate)) { + const liabilitiesDate = new Date(date); + const todaysDate = new Date(); + if (liabilitiesDate > todaysDate) { alert('Input Date cannot be in the future'); return false; } -- GitLab From 7d7e6d2abe7c7c72a0ed940498027fa729e73957 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Mon, 26 Jun 2017 16:24:20 -0400 Subject: [PATCH 09/20] Change name of liabilities form. --- blocnote/apps/financialInputs/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blocnote/apps/financialInputs/forms.py b/blocnote/apps/financialInputs/forms.py index 8324924..bd7e57f 100644 --- a/blocnote/apps/financialInputs/forms.py +++ b/blocnote/apps/financialInputs/forms.py @@ -35,7 +35,7 @@ class CustomerPreferenceForm(ModelForm): ] -class Liabilitiesform(ModelForm): +class LiabilitiesForm(ModelForm): """Define the form that validates the liabilities records of the customer.""" class Meta: -- GitLab From fc235dde8e651eb22df8088afcdbbe9eac56506a Mon Sep 17 00:00:00 2001 From: Adarsh Date: Mon, 26 Jun 2017 16:25:18 -0400 Subject: [PATCH 10/20] Update liaiblites to use the form to validate data and return an error dictionary if errors are present. --- .../apps/financialInputs/views/liabilities.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/blocnote/apps/financialInputs/views/liabilities.py b/blocnote/apps/financialInputs/views/liabilities.py index 123b162..85c86d0 100644 --- a/blocnote/apps/financialInputs/views/liabilities.py +++ b/blocnote/apps/financialInputs/views/liabilities.py @@ -5,6 +5,7 @@ from django.views import View from django.http import JsonResponse from blocnote.apps.financialInputs.models import Liabilities +from blocnote.apps.financialInputs.forms import LiabilitiesForm class LiabilitiesTable(View): """Store and load Mortgage and Liability information for a building id.""" @@ -53,8 +54,15 @@ class LiabilitiesTable(View): put = json.loads(request.body.decode()) for record in put: record['building_id'] = building_id - self.model.objects.update_or_create( - building_id=building_id, - defaults=record, - ) + form = LiabilitiesForm(record) + if form.is_valid(): + self.model.objects.update_or_create( + building_id=building_id, + defaults=record, + ) + else: + error_dict = {} + for field, error in form.errors.items(): + error_dict[field] = error + return JsonResponse(error_dict, status=400) return JsonResponse({}) -- GitLab From 445e2b34f308df17274e1b382724645b85082774 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Mon, 26 Jun 2017 16:37:43 -0400 Subject: [PATCH 11/20] Display error messages when PUT requests return status 400 response. --- .../static/financialInputs/scripts/liabilities.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js index 46eb611..383b7e7 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js @@ -99,10 +99,20 @@ function liabilitiesSubmitForm(form) { 'X-CSRFToken': Cookies.get('csrftoken') }) }).then(res => { - if (!res.payload.err) { + if (!res.err) { document.querySelector('#liabilities-warning-message').innerHTML = ` Saved! `; + } else { + res.err.responseBody.then((error) => { + let errorMsg = ''; + Object.keys(error).forEach((key) => { + errorMsg += `${key}: ${error[key]}\n`; + }); + document.querySelector('#liabilities-warning-message').innerHTML = ` + ${errorMsg} + `; + }); } }); return false; -- GitLab From d4a813c47bd663377dffd758dece06385a0310d2 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Mon, 26 Jun 2017 16:42:30 -0400 Subject: [PATCH 12/20] Display liability table if no error occured. --- .../static/financialInputs/scripts/liabilities.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js index 383b7e7..5552287 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js @@ -127,7 +127,9 @@ function getLiabilitiesTable() { 'Content-Type': 'application/json' }, }).then(res => { - loadLiabilitiesTable(res.payload.instance); + if (!res.err) { + loadLiabilitiesTable(res.payload.instance); + } }); } -- GitLab From bea497ff6ff9a36af74c2f728cdb4b2d8b963be2 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Mon, 26 Jun 2017 16:44:43 -0400 Subject: [PATCH 13/20] Move getLiabilities from app js to liability. --- .../apps/financialInputs/static/financialInputs/scripts/app.js | 1 - .../static/financialInputs/scripts/liabilities.js | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js index ad2dcb1..0db1780 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js @@ -11,7 +11,6 @@ for (var utility_index in utilities) { loadBillsOverview(); getIncomeStatementTable(); -getLiabilitiesTable(); getCashBalanceForm(); getLoanOptionsTable(); diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js index 5552287..7e88d10 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js @@ -133,3 +133,4 @@ function getLiabilitiesTable() { }); } +getLiabilitiesTable(); -- GitLab From d7391fac9aa8c07d32884d954905e877dd24e5d5 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Wed, 28 Jun 2017 14:16:03 -0400 Subject: [PATCH 14/20] Move misplaced else. --- .../static/financialInputs/scripts/liabilities.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js index 7e88d10..b83a2c7 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js @@ -6,8 +6,7 @@ function loadLiabilitiesTable(inputList) { if (inputList.length === 0) { addLiabilitiesRow('', '', '', ''); - } - else { + } else { inputList.map(function(record, index) { record = inputList[index]; let lender = record['lender']; -- GitLab From 135318a54beb07e056d7ec23418ba81725073d7e Mon Sep 17 00:00:00 2001 From: Adarsh Date: Wed, 28 Jun 2017 14:33:48 -0400 Subject: [PATCH 15/20] Rename all the cells to the corresponding input fields. --- .../financialInputs/scripts/liabilities.js | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js index b83a2c7..dccfd52 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js @@ -23,26 +23,26 @@ function addLiabilitiesRow(lender, service, term, date) { const table = document.querySelector('#liabilities-table tbody'); const rowCount = table.rows.length; let row = table.insertRow(rowCount); - let cell = row.insertCell(0); - cell.innerHTML = `Debt ${rowCount + 1}`; - cell = row.insertCell(1); - cell.innerHTML = ` + const debtCell = row.insertCell(0); + debtCell.innerHTML = `Debt ${rowCount + 1}`; + const lenderCell = row.insertCell(1); + lenderCell.innerHTML = ` `; - cell = row.insertCell(2); - cell.innerHTML = ` + const monthlyServiceCell = row.insertCell(2); + monthlyServiceCell.innerHTML = ` `; - cell = row.insertCell(3); - cell.innerHTML = ` + const remainingTermCell = row.insertCell(3); + remainingTermCell.innerHTML = ` `; - cell = row.insertCell(4); - cell.innerHTML = ` + const dateCell = row.insertCell(4); + dateCell.innerHTML = ` `; - cell = row.insertCell(5); - cell.innerHTML = ` + const deleteButtonCell = row.insertCell(5); + deleteButtonCell.innerHTML = `
-- GitLab From 61209e5b076d55e6eacf57e6e5a1bedc7660cfad Mon Sep 17 00:00:00 2001 From: Adarsh Date: Wed, 28 Jun 2017 14:36:19 -0400 Subject: [PATCH 16/20] Rename rowInd to rowIndex. --- .../static/financialInputs/scripts/liabilities.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js index dccfd52..24df198 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js @@ -56,9 +56,9 @@ function deleteLiabilitiesRow(rowIndex) { const table = document.querySelector('#liabilities-table'); table.deleteRow(rowIndex); const rowCount = table.rows.length; - for (let rowInd = 1; rowInd < rowCount; rowInd++) { - let row = table.rows.item(rowInd).cells; - row.item(0).innerHTML = `Debt ${rowInd}`; + for (let rowIndex = 1; rowIndex < rowCount; rowIndex++) { + let row = table.rows.item(rowIndex).cells; + row.item(0).innerHTML = `Debt ${rowIndex}`; } } return false; -- GitLab From 83696bc1cb5176ee411abfe7a8e2d07d9b73cd23 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Wed, 28 Jun 2017 14:41:50 -0400 Subject: [PATCH 17/20] Change comments for the 2 new functions . --- .../static/financialInputs/scripts/liabilities.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js index 24df198..63c8b8f 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js @@ -69,7 +69,7 @@ liabilitiesForm.onchange = function() { document.querySelector('#liabilities-warning-message').innerHTML = ''; }; -/**HTTP PUT request with the user inputs for Mortgage and Liability. */ +/**Submit morgage and other liabilities information for a building.*/ function liabilitiesSubmitForm(form) { const table = document.querySelector('#liabilities-table'); const rowCount = table.rows.length; @@ -117,7 +117,7 @@ function liabilitiesSubmitForm(form) { return false; } -/**HTTP GET request for any Mortgage and Liability data for the building id. */ +/**Get mortgage and other liabilities information for a building.*/ function getLiabilitiesTable() { request('liabilities/', { method: 'GET', -- GitLab From 94082916b69db0422ba4cb0212596f4e349712bd Mon Sep 17 00:00:00 2001 From: Adarsh Date: Wed, 28 Jun 2017 15:08:54 -0400 Subject: [PATCH 18/20] Rename all the rowInd to rowIndex. --- .../static/financialInputs/scripts/liabilities.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js index 63c8b8f..e2c7d89 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js @@ -74,12 +74,12 @@ function liabilitiesSubmitForm(form) { const table = document.querySelector('#liabilities-table'); const rowCount = table.rows.length; let result = []; - for (let rowInd = 1; rowInd < rowCount; rowInd++) { + for (let rowIndex = 1; rowIndex < rowCount; rowIndex++) { let record = {}; - record['lender'] = table.rows[rowInd].cells[1].children[0].value; - record['monthly-service'] = table.rows[rowInd].cells[2].children[0].value; - record['remaining-term'] = table.rows[rowInd].cells[3].children[0].value; - let date = table.rows[rowInd].cells[4].children[0].value; + record['lender'] = table.rows[rowIndex].cells[1].children[0].value; + record['monthly-service'] = table.rows[rowIndex].cells[2].children[0].value; + record['remaining-term'] = table.rows[rowIndex].cells[3].children[0].value; + let date = table.rows[rowIndex].cells[4].children[0].value; const liabilitiesDate = new Date(date); const todaysDate = new Date(); if (liabilitiesDate > todaysDate) { -- GitLab From 7c717e3e7b4667ed5d99e99bb486fb58a2e31256 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Thu, 29 Jun 2017 08:48:10 -0400 Subject: [PATCH 19/20] Remove print statement. --- blocnote/apps/financialInputs/old_views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/blocnote/apps/financialInputs/old_views.py b/blocnote/apps/financialInputs/old_views.py index 03770d7..2be3ee6 100644 --- a/blocnote/apps/financialInputs/old_views.py +++ b/blocnote/apps/financialInputs/old_views.py @@ -427,7 +427,6 @@ class BillsOverviewView(View): projected_bills['oil_user'] = o_user projected_bills['water_user'] = w_user total_annual_charge = [] - print(projected_bills) for year in range(analysis_date['proforma_duration']): total = 0 store_year = str(analysis_date['proforma_start'].year + year) -- GitLab From 2b3c2a93e9bfb43d9614b8b60aae60c80ca35e51 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Thu, 29 Jun 2017 08:50:31 -0400 Subject: [PATCH 20/20] Remove liaiblities code from old views. --- blocnote/apps/financialInputs/old_views.py | 54 +--------------------- 1 file changed, 1 insertion(+), 53 deletions(-) diff --git a/blocnote/apps/financialInputs/old_views.py b/blocnote/apps/financialInputs/old_views.py index 2be3ee6..d8c232b 100644 --- a/blocnote/apps/financialInputs/old_views.py +++ b/blocnote/apps/financialInputs/old_views.py @@ -10,7 +10,7 @@ from bpfin.back_end_call.back_end_inputs import monthly_bill, form_prior_income_ from blocnote.lib.fetch_data import get_building_data from .models import ( - FinancingOverview, Bills, BillsOverview, EstimationAlgorithm, Liabilities, IncomeStatement, + FinancingOverview, Bills, BillsOverview, EstimationAlgorithm, IncomeStatement, LoanOptions, DefaultLoan, Lender, GrowthRate ) @@ -485,58 +485,6 @@ class BillsOverviewView(View): return JsonResponse({}) -class LiabilitiesTable(View): - """Store and load Mortgage and Liability information for a building id.""" - - model = Liabilities - - def get(self, request, building_id): - """HTTP GET request. - - Fetch Mortgage and Liability information from the database and return to the frontend. - - Returns: - JsonResponse: List of records. Each record is a dictionary with key as the attribute name and value - as the value. - """ - objs = self.model.objects.filter(building_id=building_id) - result = [] - if objs: - for obj in objs: - record = { - 'lender': obj.lender, - 'input_date': obj.input_date, - 'monthly_service': obj.monthly_service, - 'remaining_term': obj.remaining_term, - } - result.append(record) - return JsonResponse({'instance': result}) - - def put(self, request, building_id): - """HTTP PUT request. - - Receive Mortgage and Liabilities data from frontend and store in the database. Delete any existing records - before storing new data. - Args: - request: HTTP PUT request. - building_id: id of the building. - - Returns: - JsonResponse: A status saying OK. - """ - put = json.loads(request.body.decode()) - self.model.objects.filter(building_id=building_id).delete() - for record in put: - self.model.objects.create( - building_id=building_id, - input_date=record['input_date'], - lender=record['lender'], - monthly_service=float(record['monthly-service']), - remaining_term=float(record['remaining-term']), - ) - return JsonResponse({}) - - class IncomeStatementTable(View): """Income Statement table. -- GitLab