Skip to content

Commit

Permalink
Merge pull request #77 from jeremiahbrem/form-add-61
Browse files Browse the repository at this point in the history
added reminder form, tests, and fixed ocsn dockets url
  • Loading branch information
syk1112 authored Jul 11, 2020
2 parents cd3d983 + 178c70b commit bb3393c
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 5 deletions.
15 changes: 15 additions & 0 deletions static/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,21 @@ footer a:hover {
color: #333;
}

#case-form {
max-width: 500px;
margin-right: auto;
margin-left: auto;
}

.form-group {
position: relative;
}

label {
float: left;
margin-left: 20px;
}

/* Tablet Breakpoint */
@media all and (min-width: 768px) {
.display-1, h1 {
Expand Down
3 changes: 3 additions & 0 deletions website/templates/base_generic.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
<li class="nav-item">
<a class="nav-link" href="#about">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#form">Get Case Reminder</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#faq">FAQ</a>
</li>
Expand Down
44 changes: 41 additions & 3 deletions website/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ <h1 class="display-1">Get Court Date Reminders</h1>
<!-- <div class="col-sm-4 display-3">Rogers <br />County<br /><a class="btn btn-lg btn-yellow" style="font-size:20px" href="sms:9182059352">(918)-205-9352</a></div> -->
<!-- <div class="col-sm-4 display-3">Tulsa <br />County<br /><a class="btn btn-lg btn-yellow" style="font-size:20px" href="sms:9189923222">(918)-992-3222</a></div> -->
</div>



</div>
</div>
Expand Down Expand Up @@ -60,8 +62,44 @@ <h4>FEWER FINES</h4>
</article>
</div>
</section>
<!-- Case Reminder Form -->
<section id="form">
<div class="container text-center">
{% if messages %}
{% for message in messages %}
<p{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</p>
{% endfor %}
{% endif %}
<h2>Fill Out Reminder Form:</h2>
<form action="/schedule_reminders" id="case-form" method="POST">
<div class="form-group">
<label for="case_num">Case Number <small>(ex: CF-1234-5678)</small></label>
<input type="text" class="form-control" id="case_num" name="case_num" placeholder="Enter case number" required>
</div>
<div class="form-group">
<label for="year">Year Filed</label>
<input type="number" class="form-control" id="year" name="year" min="2000" max="2100" placeholder="Enter year filed" required>
</div>
<div class="form-group">
<label for="county">County</label>
<input type="text" class="form-control" id="county" name="county" placeholder="Enter county" required>
</div>
<div class="form-group">
<label for="phone_num">Reminder Phone Number <small>(ex: 918-123-4567)</small></label>
<input type="tel" class="form-control" id="phone_num" name="phone_num" placeholder="Enter Phone Number"
pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" required>
</div>
<div class="form-group">
<label for="add_phone_num">Additional Phone Number</label>
<input type="tel" class="form-control" id="add_phone_num" name="add_phone_num" placeholder="Enter Phone Number"
pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</section>
<!--FAQs-->
<section id="faq">
<section id="faq" class="CBLtBgClr">
<div class="container">
<h2 class="center">Frequently Asked Questions</h2>
<br>
Expand All @@ -72,7 +110,7 @@ <h4>1. How do I know my OSCN Case Number?</h4>
</div>
<div class="col-sm-6">
<h4>2. What if I still can't find my case number?</h4>
<p>Check with your public defender or search your name online at <a href=“www.oscn.net/docets/search.aspx”>www.oscn.net/docets/search.aspx </a> </p> </div> <div class="col-sm-6">
<p>Check with your public defender or search your name online at <a href=“www.oscn.net/dockets/search.aspx”>www.oscn.net/dockets/search.aspx </a> </p> </div> <div class="col-sm-6">
<h4>3. Can other people be reminded of my court date?</h4>
<p>Anyone with your case number will be able to use courtbot to keep track of your court date.</p>
</div>
Expand Down Expand Up @@ -100,7 +138,7 @@ <h4>8. How do I contact the people behind CourtBot?</h4>
</div>
</section>
<!--Credits-->
<section class="CBLtBgClr">
<section>
<div id="sponsor-logo" class="container text-center ">
<h3>Brought to you by</h3>
<br>
Expand Down
46 changes: 44 additions & 2 deletions website/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
from django.test import TestCase
from django.test import TestCase, RequestFactory, Client
import json

class testFormViews(TestCase):

def setUp(self):
self.factory = RequestFactory()
self.client = Client()

def test_form_data_view_passed(self):
data = {
"case_num": "CF-2020-1648",
"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)

self.assertIn(str.encode("Arraignment for case CF-2020-1648 has already passed"), resp.content)

def test_form_data_view_not_found(self):
data = {
"case_num": "1000000000",
"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)

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",
"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)

self.assertIn(str.encode("Reminder scheduled"), resp.content)

# Create your tests here.
1 change: 1 addition & 0 deletions website/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

urlpatterns = [
path('', views.index, name='index'),
path('schedule_reminders', views.schedule_reminders, name='schedule_reminders')
]
67 changes: 67 additions & 0 deletions website/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,74 @@
from django.shortcuts import render, redirect
from datetime import datetime, timedelta
import re

from django.http import JsonResponse, HttpResponse
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
from django.contrib import messages

import oscn, requests, json


from alerts.models import Alert

def index(request):
# """View function for home page of site."""

# Render the HTML template index.html with the data in the context variable
return render(request, 'index.html')

def check_valid_case(request):
# 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}"
)
resp_json = json.loads(resp.content)
if resp_json.get('error', None):
return resp_json['error'], None
return '', resp_json.get('arraignment_datetime', None)


def set_case_reminder(arraignment_datetime, case_num, phone_num):
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}"
})
resp = json.loads(reminder_request.content)
if resp.get('error', None):
return False, resp['error']
message = f'Text reminder for case {case_num} occuring on {arraignment_datetime} was scheduled under {phone_num}.'
return True, message


@csrf_exempt
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']
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)
return redirect('/#form')

0 comments on commit bb3393c

Please sign in to comment.