Skip to content

Commit

Permalink
Add Web UI
Browse files Browse the repository at this point in the history
...and overcommit

Change-Id: I30e2e501681549f7a7235f0b7eb62ee4d20afdd9
Reviewed-on: https://code.brigade.com/1586
Reviewed-by: Tom Dooner <[email protected]>
Tested-by: Tom Dooner <[email protected]>
  • Loading branch information
tdooner committed Jun 18, 2015
1 parent 9b92b25 commit 9ec062e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 4 deletions.
30 changes: 30 additions & 0 deletions .overcommit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
CommitMsg:
GerritChangeId:
enabled: true

HardTabs:
enabled: true


PreCommit:
ALL:
exclude:
- 'vendor/**/*'

AuthorEmail:
enabled: true
description: 'Checking author email for Brigade domain'
***REMOVED***

HardTabs:
enabled: true
description: 'Checking for hard tabs'

JsonSyntax:
enabled: true

MergeConflicts:
enabled: true

TrailingWhitespace:
enabled: true
48 changes: 44 additions & 4 deletions web.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
import os

***REMOVED***
***REMOVED***
***REMOVED***

Expand Down Expand Up @@ -50,12 +51,50 @@ def with_validation():
@app.route('/')
def home():
return """
<form method='POST' action='/match'>
<form id="test-form" method='POST' action='/match'>
***REMOVED***
***REMOVED***
<input name='dob' value='1991-01-01' placeholder='DOB (yyyy-mm-dd)' />
<input name='dob' value='1991-01-01' placeholder='DOB (yyyy-mm-dd)' /><br />
<input name='state' value='OH' placeholder='State (OH)' />
<input type='submit' />
</form>
<hr />
<div id="result">No results.</div>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script type="text/javascript">
$("#test-form").on('submit', function(e) {
e.preventDefault();
var query = {
"first_name": $("input[name=first_name]").val(),
"last_name": $("input[name=last_name]").val(),
"dob": $("input[name=dob]").val()
};
var state = $("input[name=state]").val();
if (state.length) {
query["state"] = state;
}
$.ajax({
"url": "/v1/voters/search",
"type": "POST",
"contentType": "application/json",
"data": JSON.stringify({
"user": query
}),
"success": function(resp, status, xhr) {
$("#result").html("<ul></ul>");
var results = resp["data"];
for (var i in results) {
$("#result ul").append("<li>" + JSON.stringify(results[i]) + "</li>");
}
}
});
});
</script>
"""


Expand All @@ -77,9 +116,10 @@ def search(params):
entry in a voter roll.
"""
if 'dob' in params['user']:
params['user']['dob'] = datetime.strptime(params['user']['dob'], "%Y-%m-%d")
year, month, day = params['user']['dob'].split("-")
params['user']['dob'] = NullableDate(year=int(year), month=int(month), day=int(day))

matches = match_many(**params['user']),
matches = match_many(**params['user'])
resp = json.dumps({'data': matches}, sort_keys=True, indent=4, separators=(',', ': '))

return resp, 200, {'Content-Type': 'application/json'}
Expand Down

0 comments on commit 9ec062e

Please sign in to comment.