team-3/src/c3nav/site/views.py

43 lines
1.1 KiB
Python
Raw Normal View History

2016-12-15 18:28:04 +01:00
from django.shortcuts import redirect, render
2016-12-15 17:30:55 +01:00
from c3nav.mapdata.models.locations import get_location
2016-12-16 17:38:13 +01:00
from c3nav.routing.graph import Graph
2016-12-15 17:30:55 +01:00
2016-12-15 18:28:04 +01:00
def main(request, origin=None, destination=None):
do_redirect = False
if origin:
origin_obj = get_location(request, origin)
if origin_obj.name != origin:
do_redirect = True
origin = origin_obj
if destination:
destination_obj = get_location(request, destination)
if destination_obj.name != destination:
do_redirect = True
destination = destination_obj
if do_redirect:
new_url = '/'
if origin:
new_url += origin.name+'/'
if destination:
new_url += destination.name + '/'
elif destination:
new_url += '_/' + destination.name + '/'
redirect(new_url)
2016-12-16 17:38:13 +01:00
if origin and destination:
graph = Graph.load()
route = graph.get_route(origin, destination)
print(route)
2016-12-15 18:28:04 +01:00
return render(request, 'site/main.html', {
'origin': origin,
'destination': destination
})