This repository has been archived by the owner on Aug 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
views.py
51 lines (42 loc) · 1.61 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from flask import Flask
app = Flask(__name__)
from flask import render_template, redirect, request
import traceback
import logging
from lib.distances import *
from lib.elevation import *
@app.route('/', methods=['GET'])
@app.route('/index', methods=['GET'])
def show_form():
'''Shows the homepage, with a search form'''
return render_template('indextemplate.html')
@app.route('/results', methods=['POST', 'GET'])
def show_results():
'''Calls the backend functions to obtain data, which is then shown'''
try:
start = [float(request.form['lat_a']),
float(request.form['long_a'])]
end = [float(request.form['lat_b']),
float(request.form['long_b'])]
except Exception as e:
print "Error caught:\n",e
return redirect('/error')
else:
delta_h = getheight(start, end, KEY, BASEURL)
dist = haversine(start, end)/1000 #in km
nearest_lock = find_nearest_bike_parking(end)
#plus a bunch more cool things
return render_template('resultstemplate.html',
searched=request.form,
delta_h=delta_h,
dist=dist,
nearest_lock=nearest_lock) #etc
@app.route('/error')
def show_error():
return render_template('errortemplate.html')
# --------------------------------------------------
# placeholder functions
# these will be deleted once the functions to import are written
def elevation(a, b):
'''takes a start and end and returns the change in elevation'''
return 3.14