Skip to content

Commit

Permalink
Merge pull request #21 from SeattleDSA/feature/search-improvement
Browse files Browse the repository at this point in the history
Feature/search improvement
  • Loading branch information
mpuckett159 authored Dec 9, 2020
2 parents fa5e173 + e3ca5a7 commit 0e1766f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 28 deletions.
50 changes: 41 additions & 9 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask, render_template
from flask import Flask, render_template, request, redirect, url_for

import dataset


app = Flask(__name__, static_folder="public", template_folder="views")


################################################################################
# Home page reroute
################################################################################
@app.route("/")
def home():
"""Reroute home URL to license lookup form"""
return redirect(url_for('license_page'))


################################################################################
# Licenses
################################################################################
Expand All @@ -16,14 +25,22 @@
"entity_name_long": "license plate",
"entity_name_short": "License #",
"data_source": "https://data.seattle.gov/City-Business/Active-Fleet-Complement/enxu-fgzb",
"lookup_url": "license-lookup",
"lookup_url": "license",
"query_param": "license"
}


@app.route("/")
@app.route("/license")
def license_page():
"""Displays the homepage."""
return render_template("index.html", **LICENSE_CONTEXT)
"""License lookup form render"""
# Check for badge query params and load if it exists.
license = request.args.get('license')
html = ""
if license:
html = dataset.license_lookup(license)

# Return the basic lookup form if not
return render_template("index.html", **LICENSE_CONTEXT, entity_html=html)


@app.route("/license-lookup/<license>")
Expand All @@ -40,13 +57,21 @@ def license_lookup(license):
"entity_name_long": "badge number",
"entity_name_short": "Badge #",
"data_source": "https://data.seattle.gov/City-Business/City-of-Seattle-Wage-Data/2khk-5ukd",
"lookup_url": "badge-lookup",
"lookup_url": "badge",
"query_param": "badge"
}


@app.route("/badge")
def badge_page():
return render_template("index.html", **BADGE_CONTEXT)
"""Badge lookup form render"""
# Check for badge query params and load if it exists.
badge = request.args.get('badge')
html = ""
if badge:
html = dataset.badge_lookup(badge)

return render_template("index.html", **BADGE_CONTEXT, entity_html=html)


@app.route("/badge-lookup/<badge>")
Expand All @@ -63,13 +88,20 @@ def badge_lookup(badge):
"entity_name_long": "last name",
"entity_name_short": "Lastname",
"data_source": "https://data.seattle.gov/City-Business/City-of-Seattle-Wage-Data/2khk-5ukd",
"lookup_url": "name-lookup",
"lookup_url": "name",
"query_param": "last"
}


@app.route("/name")
def name_page():
return render_template("index.html", **NAME_CONTEXT)
"""Officer name lookup form render"""
last_name = request.args.get('last')
html = ""
if last_name:
html = dataset.name_lookup(last_name)

return render_template("index.html", **NAME_CONTEXT, entity_html=html)


@app.route("/name-lookup/<name>")
Expand Down
22 changes: 3 additions & 19 deletions src/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h1>

<main>
<div>
<form action="/" class="form_override">
<form action="/license" class="form_override">
<button type="submit">Licenses</button>
</form>
<form action="/badge" class="form_override">
Expand All @@ -30,8 +30,8 @@ <h1>
</div>
<p class="bold">{{ title }}</p>
<p>Enter in a {{ entity_name_long }}</p>
<form id="main_form">
<input type="text" maxlength="100" placeholder="{{ entity_name_short }}">
<form action="/{{ lookup_url }}" method="GET">
<input id="{{ query_param }}" name="{{ query_param }}" placeholder="{{ entity_name_short }}">
<button type="submit">Submit</button>
</form>
<section class="dreams">
Expand All @@ -46,21 +46,5 @@ <h1>
<a href="http://twitter.com/AetherUnbound">If I break message my mom</a>
</footer>


<!-- Your web-app is https, so your scripts need to be too -->
<script src="https://code.jquery.com/jquery-2.2.1.min.js"
integrity="sha256-gvQgAFzTH6trSrAWoH1iPo9Xc96QxSZ3feW6kem+O00="
crossorigin="anonymous"></script>
<script>
$(function() {
$('#main_form').submit(function(event) {
event.preventDefault();
var entity = $('input').val();
window.location.replace("/{{lookup_url}}/" + entity)
});

});
</script>

</body>
</html>

0 comments on commit 0e1766f

Please sign in to comment.