From d5c6830e04fcddcd855adeb2ee16503453e890dc Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Mon, 14 Dec 2020 20:06:47 -0600 Subject: [PATCH 1/5] change backend only --- website/templates/index.html | 5 ++++ website/views.py | 55 +++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/website/templates/index.html b/website/templates/index.html index 9d4a5261..ee88648e 100644 --- a/website/templates/index.html +++ b/website/templates/index.html @@ -94,6 +94,11 @@

Fill Out Reminder Form:

+
+ + +
+ diff --git a/website/views.py b/website/views.py index 2e08e048..5c18a4af 100644 --- a/website/views.py +++ b/website/views.py @@ -19,15 +19,11 @@ def index(request): # Render the HTML template index.html with the data in the context variable return render(request, 'index.html') -def check_valid_case(request): +def check_valid_case(case_num, year, county): # Process form data and requests arraignment data form api/case - case_num = request.POST['case_num'] - year = request.POST['year'] - county = request.POST['county'] - phone_num = request.POST['phone_num'] - add_num = request.POST['add_phone_num'] resp = requests.get( - f"https://courtbot-python.herokuapp.com/api/case?year={year}&county={county}&case_num={case_num}" + #f"https://courtbot-python.herokuapp.com/api/case?year={year}&county={county}&case_num={case_num}" + f"http://127.0.0.1:8000/api/case?year={year}&county={county}&case_num={case_num}" ) resp_json = json.loads(resp.content) if resp_json.get('error', None): @@ -36,7 +32,8 @@ def check_valid_case(request): def set_case_reminder(arraignment_datetime, case_num, phone_num): - reminder_request = requests.post('https://courtbot-python.herokuapp.com/api/reminders', { + #reminder_request = requests.post('https://courtbot-python.herokuapp.com/api/reminders', { + reminder_request = requests.post('http://127.0.0.1:8000/api/reminders', { "arraignment_datetime": arraignment_datetime, "case_num": case_num, "phone_num": f"+1-{phone_num}" @@ -52,25 +49,31 @@ def set_case_reminder(arraignment_datetime, case_num, phone_num): def schedule_reminders(request): # If valid case and arraignment time, posts reminder data to api/reminder # Includes option for extra phone number for additional recipient - case_num = request.POST['case_num'] + #case_num = request.POST['case_num'] + case_num_list = [ + value for key, value in request.POST.items() + if key.find("case_num") > -1 and value + ] + year = request.POST['year'] + county = request.POST['county'] phone_num = request.POST['phone_num'] add_num = request.POST.get('add_phone_num', None) - - valid_case_message, arraignment_datetime = check_valid_case(request) - if not arraignment_datetime: - messages.error(request, valid_case_message) - faq_message = ( - f'Please check the case for further information using steps provided at http://court.bot/#faq' - ) - messages.error(request, faq_message) - else: - reminder_set, reminder_message = set_case_reminder(arraignment_datetime, case_num, phone_num) - # messages.error(request, message) - messages.info(request, reminder_message) - if not reminder_set: - return redirect('/#form') - if add_num: - _, another_reminder_message = set_case_reminder(arraignment_datetime, case_num, add_num) - messages.info(request, another_reminder_message) + for case_num in case_num_list: + valid_case_message, arraignment_datetime = check_valid_case(case_num, year, county) + if not arraignment_datetime: + messages.error(request, valid_case_message) + faq_message = ( + f'Please check the case for further information using steps provided at http://court.bot/#faq' + ) + messages.error(request, faq_message) + else: + reminder_set, reminder_message = set_case_reminder(arraignment_datetime, case_num, phone_num) + # messages.error(request, message) + messages.info(request, reminder_message) + if not reminder_set: + return redirect('/#form') + if add_num: + _, another_reminder_message = set_case_reminder(arraignment_datetime, case_num, add_num) + messages.info(request, another_reminder_message) return redirect('/#form') From 2fa0cb5173332d11db13a1ab34902193ec7e5ba1 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Sun, 27 Dec 2020 20:19:21 -0600 Subject: [PATCH 2/5] add additional field dynamically --- .gitignore | 1 + courtbot/settings.py | 2 +- note | 1 + website/templates/index.html | 41 ++++++++++++++++++++++++++++++------ website/tests.py | 12 ++++++----- website/urls.py | 2 +- website/views.py | 1 - 7 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 note diff --git a/.gitignore b/.gitignore index b3f76f86..8757559b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .env __pycache__ db.sqlite3 +env/ diff --git a/courtbot/settings.py b/courtbot/settings.py index 86bd1740..2d48276e 100644 --- a/courtbot/settings.py +++ b/courtbot/settings.py @@ -138,4 +138,4 @@ os.path.join(BASE_DIR, 'static'), ] -django_heroku.settings(locals()) +#django_heroku.settings(locals()) diff --git a/note b/note new file mode 100644 index 00000000..be22fa81 --- /dev/null +++ b/note @@ -0,0 +1 @@ +Dept of Mathematics and Computer Science, Northeastern State University Tulsa, USA diff --git a/website/templates/index.html b/website/templates/index.html index ee88648e..e4842390 100644 --- a/website/templates/index.html +++ b/website/templates/index.html @@ -94,15 +94,44 @@

Fill Out Reminder Form:

-
- - -
- - + + +
diff --git a/website/tests.py b/website/tests.py index 5bb34bfc..773a4e19 100644 --- a/website/tests.py +++ b/website/tests.py @@ -15,8 +15,8 @@ def test_form_data_view_passed(self): "phone_num": 918-555-5555, "add_phone_num": 918-111-1111 } - resp = self.client.post("https://courtbot-python.herokuapp.com/form_data", data=data, follow=True) - + #resp = self.client.post("https://courtbot-python.herokuapp.com/form_data", data=data, follow=True) + resp = self.client.post("/schedule_reminders", data=data, follow=True) self.assertIn(str.encode("Arraignment for case CF-2020-1648 has already passed"), resp.content) def test_form_data_view_not_found(self): @@ -27,19 +27,21 @@ def test_form_data_view_not_found(self): "phone_num": 918-555-5555, "add_phone_num": 918-111-1111 } - resp = self.client.post("https://courtbot-python.herokuapp.com/form_data", data=data, follow=True) + #resp = self.client.post("https://courtbot-python.herokuapp.com/form_data", data=data, follow=True) + resp = self.client.post("/schedule_reminders", data=data, follow=True) self.assertIn(str.encode("Unable to find arraignment event with the following year 2020, county Tulsa, case number 1000000000"), resp.content) def test_form_data_view_scheduled(self): data = { - "case_num": "CF-2020-2803", + "case_num": "SC-2020-11082", "year": 2020, "county": "Tulsa", "phone_num": 918-555-5555, "add_phone_num": 918-111-1111 } - resp = self.client.post("https://courtbot-python.herokuapp.com/form_data", data=data, follow=True) + #resp = self.client.post("https://courtbot-python.herokuapp.com/form_data", data=data, follow=True) + resp = self.client.post("/schedule_reminders", data=data, follow=True) self.assertIn(str.encode("Reminder scheduled"), resp.content) diff --git a/website/urls.py b/website/urls.py index 83cb4ac7..a60995eb 100644 --- a/website/urls.py +++ b/website/urls.py @@ -3,5 +3,5 @@ urlpatterns = [ path('', views.index, name='index'), - path('schedule_reminders', views.schedule_reminders, name='schedule_reminders') + path('schedule_reminders', views.schedule_reminders, name='schedule_reminders'), ] \ No newline at end of file diff --git a/website/views.py b/website/views.py index 5c18a4af..ec5f7a5b 100644 --- a/website/views.py +++ b/website/views.py @@ -49,7 +49,6 @@ def set_case_reminder(arraignment_datetime, case_num, phone_num): def schedule_reminders(request): # If valid case and arraignment time, posts reminder data to api/reminder # Includes option for extra phone number for additional recipient - #case_num = request.POST['case_num'] case_num_list = [ value for key, value in request.POST.items() if key.find("case_num") > -1 and value From a1763c7f476654759d70b251b5096baf4ad586dc Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Sun, 27 Dec 2020 20:48:16 -0600 Subject: [PATCH 3/5] prevent from leaving loop until end of case num --- website/templates/index.html | 2 +- website/views.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/website/templates/index.html b/website/templates/index.html index e4842390..5ce025c8 100644 --- a/website/templates/index.html +++ b/website/templates/index.html @@ -110,7 +110,7 @@

Fill Out Reminder Form:

let additionalCaseNumLabel = document.createElement("label"); additionalCaseNumLabel.setAttribute('for', addCaseNum); - additionalCaseNumLabel.innerHTML = "Additional Case Number" ; + additionalCaseNumLabel.innerHTML = "Additional Case Number " + index.toString() ; let additionalCaseNumSmall = document.createElement("small"); additionalCaseNumSmall.innerHTML = "(ex: CF-1234-5678)" ; diff --git a/website/views.py b/website/views.py index ec5f7a5b..d0f785d7 100644 --- a/website/views.py +++ b/website/views.py @@ -57,7 +57,7 @@ def schedule_reminders(request): county = request.POST['county'] phone_num = request.POST['phone_num'] add_num = request.POST.get('add_phone_num', None) - for case_num in case_num_list: + for i, case_num in enumerate(case_num_list): valid_case_message, arraignment_datetime = check_valid_case(case_num, year, county) if not arraignment_datetime: messages.error(request, valid_case_message) @@ -69,7 +69,7 @@ def schedule_reminders(request): reminder_set, reminder_message = set_case_reminder(arraignment_datetime, case_num, phone_num) # messages.error(request, message) messages.info(request, reminder_message) - if not reminder_set: + if len(case_num_list)-1 == i and not reminder_set: return redirect('/#form') if add_num: _, another_reminder_message = set_case_reminder(arraignment_datetime, case_num, add_num) From fc357031e81e9c22bf9d89a7d16ea91d2f368b8c Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Sun, 27 Dec 2020 20:57:58 -0600 Subject: [PATCH 4/5] using heroke not local api --- website/views.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/website/views.py b/website/views.py index d0f785d7..49a34a6f 100644 --- a/website/views.py +++ b/website/views.py @@ -22,8 +22,8 @@ def index(request): def check_valid_case(case_num, year, county): # Process form data and requests arraignment data form api/case resp = requests.get( - #f"https://courtbot-python.herokuapp.com/api/case?year={year}&county={county}&case_num={case_num}" - f"http://127.0.0.1:8000/api/case?year={year}&county={county}&case_num={case_num}" + #f"http://127.0.0.1:8000/api/case?year={year}&county={county}&case_num={case_num}" + f"https://courtbot-python.herokuapp.com/api/case?year={year}&county={county}&case_num={case_num}" ) resp_json = json.loads(resp.content) if resp_json.get('error', None): @@ -32,8 +32,8 @@ def check_valid_case(case_num, year, county): def set_case_reminder(arraignment_datetime, case_num, phone_num): - #reminder_request = requests.post('https://courtbot-python.herokuapp.com/api/reminders', { - reminder_request = requests.post('http://127.0.0.1:8000/api/reminders', { + #reminder_request = requests.post('http://127.0.0.1:8000/api/reminders', { + reminder_request = requests.post('https://courtbot-python.herokuapp.com/api/reminders', { "arraignment_datetime": arraignment_datetime, "case_num": case_num, "phone_num": f"+1-{phone_num}" From 96df42ef9f9051a236241ad1524456923a7320c2 Mon Sep 17 00:00:00 2001 From: Hiroyuki Terauchi <44413241+hiroTochigi@users.noreply.github.com> Date: Sun, 27 Dec 2020 20:59:01 -0600 Subject: [PATCH 5/5] Delete note --- note | 1 - 1 file changed, 1 deletion(-) delete mode 100644 note diff --git a/note b/note deleted file mode 100644 index be22fa81..00000000 --- a/note +++ /dev/null @@ -1 +0,0 @@ -Dept of Mathematics and Computer Science, Northeastern State University Tulsa, USA