Skip to content

Commit

Permalink
Merge branch 'thealphadollar-add_link_search'
Browse files Browse the repository at this point in the history
  • Loading branch information
themousepotato committed Oct 17, 2018
2 parents 12112e5 + fcadcb1 commit 12586a8
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 67 deletions.
5 changes: 3 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ def fetch_results(prof):
def result():
prof = request.form['prof']
tb, times, dept, website, prof = fetch_results(prof)
return render_template('main.html', name=prof, website=website, data=tb, times=times, profs=profs, dept=dept)
return render_template('main.html', name=prof, website=website, data=tb, times=times, profs=profs, dept=dept, error=False)


@app.errorhandler(404)
def prof_not_found(error):
return render_template('404.html'), 404
prof = request.form['prof']
return render_template('main.html', error=True, name=prof), 404


@app.route('/', methods=['GET'])
Expand Down
37 changes: 0 additions & 37 deletions templates/404.html

This file was deleted.

100 changes: 72 additions & 28 deletions templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ <h1 class="text-center display-2">
method="post"
id="search"
class="text-center">
<input list="profs" name="prof"
placeholder="Who are you looking for?"
class="form-control">
{% if name %}
<input list="profs" name="prof"
placeholder="Who are you looking for?"
class="form-control" id="prof_query" value="{{name}}">
{% else %}
<input list="profs" name="prof"
placeholder="Who are you looking for?"
class="form-control" id="prof_query">
{% endif %}
<input type="submit" value="Get timetable"
style="margin-top:20px;margin-bottom:10px"
class="btn btn-md btn-primary">
Expand All @@ -76,33 +82,60 @@ <h1 class="text-center display-2">
</div>
</div>
<div class="row">
{% if name %}
<h3 class="display-4"> <a href="{{ website }}" target="_blank"> {{ name }} </a> | {{ dept }} </h3>
<table class="table table-striped table-bordered table-hover
text-center">
<thead class="thead-light">
<tr>
{% for time in times %}
<th class="col-md-1"> {{time}} </th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in data %}
<tr>
{% for col in row %}
<td class="col-md-1" style="padding: 0;">
{% for venue in col %}
<div class="venue">
{{ venue }}
</div>
{% if not error %}
{% if name %}
<h3 class="display-4"> <a href="{{ website }}" target="_blank"> {{ name }} </a> | {{ dept }} </h3>
<table class="table table-striped table-bordered table-hover
text-center">
<thead class="thead-light">
<tr>
{% for time in times %}
<th class="col-md-1"> {{time}} </th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in data %}
<tr>
{% for col in row %}
<td class="col-md-1" style="padding: 0;">
{% for venue in col %}
<div class="venue">
{{ venue }}
</div>
{% endfor %}
</td>
{% endfor %}
</td>
</tr>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</tbody>
</table>
{% endif %}
{% endif %}

{% if error %}
<div style="margin-top: 4%; margin-bottom: 4%" class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="error-template text-center">
<h1>Oops!</h1>
<h2>Professor Not Found!</h2>
<div class="error-details">
Sorry, we're unable to find the professor that you searched
for! Check the spelling of the professor's name. If you are
still unable to find their timetable, then ERP doesn't
contain their data.
</div>
<script>
document.getElementById("prof_query").focus();
</script>
</div>
</div>
<div class="col-md-3">
</div>
</div>
</div>

{% endif %}

<script>
Expand All @@ -113,6 +146,17 @@ <h3 class="display-4"> <a href="{{ website }}" target="_blank"> {{ name }} </a>
searchForm.submit();
});
</script>
<script>
var fullLink = window.location.href;
var splitLink = fullLink.split('=');
if (splitLink.length>1) {
searchQuery = splitLink[1].replace(/%20/g, " ");
var inputBox = document.getElementById("prof_query");
inputBox.value=searchQuery;
inputBox.focus();
document.getElementById("search").submit();
}
</script>
</div>
<div class="row">
<div class="col-md-12 text-center">
Expand Down

0 comments on commit 12586a8

Please sign in to comment.