diff --git a/.gitignore b/.gitignore
index b3f76f8..8757559 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 86bd174..2d48276 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/website/templates/index.html b/website/templates/index.html
index 9d4a526..5ce025c 100644
--- a/website/templates/index.html
+++ b/website/templates/index.html
@@ -94,10 +94,44 @@
diff --git a/website/tests.py b/website/tests.py
index 5bb34bf..773a4e1 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 83cb4ac..a60995e 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 2e08e04..49a34a6 100644
--- a/website/views.py
+++ b/website/views.py
@@ -19,14 +19,10 @@ 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"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)
@@ -36,6 +32,7 @@ def check_valid_case(request):
def set_case_reminder(arraignment_datetime, case_num, phone_num):
+ #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,
@@ -52,25 +49,30 @@ 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
+ ]
+ 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 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)
+ 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 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)
+ messages.info(request, another_reminder_message)
return redirect('/#form')