site: add option to select ctypes to avoid
This commit is contained in:
parent
a63c98d8bc
commit
f9268db2d9
2 changed files with 62 additions and 26 deletions
|
@ -4,7 +4,8 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<form>
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% trans "Origin" as heading %}
|
{% trans "Origin" as heading %}
|
||||||
{% include 'site/fragment_location.html' with name='origin' location=origin heading=heading %}
|
{% include 'site/fragment_location.html' with name='origin' location=origin heading=heading %}
|
||||||
|
@ -12,6 +13,39 @@
|
||||||
{% trans "Destination" as heading %}
|
{% trans "Destination" as heading %}
|
||||||
{% include 'site/fragment_location.html' with name='destination' location=destination heading=heading %}
|
{% include 'site/fragment_location.html' with name='destination' location=destination heading=heading %}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="form-group col-md-2">
|
||||||
|
<label for="stairs-select">{% trans 'Stairs' %}</label>
|
||||||
|
<select name="stairs" id="stairs-select" class="form-control">
|
||||||
|
<option value="yes">{% trans 'allow' %}</option>
|
||||||
|
<option value="up">{% trans 'only upwards' %}</option>
|
||||||
|
<option value="down">{% trans 'only downwards' %}</option>
|
||||||
|
<option value="no">{% trans 'avoid' %}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-md-2">
|
||||||
|
<label for="escalators-select">{% trans 'Escalators' %}</label>
|
||||||
|
<select name="escalators" id="escalator-select" class="form-control">
|
||||||
|
<option value="yes">{% trans 'allow' %}</option>
|
||||||
|
<option value="up">{% trans 'only upwards' %}</option>
|
||||||
|
<option value="down">{% trans 'only downwards' %}</option>
|
||||||
|
<option value="no">{% trans 'avoid' %}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-md-2">
|
||||||
|
<label for="elevators-select">{% trans 'Elevators' %}</label>
|
||||||
|
<select name="elevators" id="elevators-select" class="form-control">
|
||||||
|
<option value="yes">{% trans 'allow' %}</option>
|
||||||
|
<option value="up">{% trans 'only upwards' %}</option>
|
||||||
|
<option value="down">{% trans 'only downwards' %}</option>
|
||||||
|
<option value="no">{% trans 'avoid' %}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-md-6">
|
||||||
|
<label for="elevators-select">{% trans 'Get Route' %}</label>
|
||||||
|
<button type="submit" id="submitbtn" class="btn btn-block btn-primary">{% trans 'Get Route' %}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% if route %}
|
{% if route %}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.http import HttpResponse
|
from django.http import Http404, HttpResponse
|
||||||
from django.shortcuts import get_object_or_404, redirect, render
|
from django.shortcuts import get_object_or_404, render
|
||||||
from PIL import Image, ImageDraw
|
from PIL import Image, ImageDraw
|
||||||
|
|
||||||
from c3nav.mapdata.models import Level
|
from c3nav.mapdata.models import Level
|
||||||
|
@ -12,37 +12,39 @@ from c3nav.mapdata.utils.misc import get_dimensions
|
||||||
from c3nav.routing.graph import Graph
|
from c3nav.routing.graph import Graph
|
||||||
from c3nav.routing.utils.draw import _line_coords
|
from c3nav.routing.utils.draw import _line_coords
|
||||||
|
|
||||||
|
ctype_mapping = {
|
||||||
|
'yes': ('up', 'down'),
|
||||||
|
'up': ('up', ),
|
||||||
|
'down': ('down', ),
|
||||||
|
'no': ()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_ctypes(prefix, value):
|
||||||
|
return tuple((prefix+'_'+direction) for direction in ctype_mapping.get(value, ('up', 'dowm')))
|
||||||
|
|
||||||
|
|
||||||
def main(request, origin=None, destination=None):
|
def main(request, origin=None, destination=None):
|
||||||
do_redirect = False
|
|
||||||
|
|
||||||
if origin:
|
if origin:
|
||||||
origin_obj = get_location(request, origin)
|
origin = get_location(request, origin)
|
||||||
if origin_obj.name != origin:
|
if origin is None:
|
||||||
do_redirect = True
|
raise Http404
|
||||||
origin = origin_obj
|
|
||||||
|
|
||||||
if destination:
|
if destination:
|
||||||
destination_obj = get_location(request, destination)
|
destination = get_location(request, destination)
|
||||||
if destination_obj.name != destination:
|
if destination is None:
|
||||||
do_redirect = True
|
raise Http404
|
||||||
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)
|
|
||||||
|
|
||||||
route = None
|
route = None
|
||||||
if origin and destination:
|
if request.method == 'POST' and origin and destination:
|
||||||
graph = Graph.load()
|
graph = Graph.load()
|
||||||
route = graph.get_route(origin, destination, ('', 'escalator_down', 'escalator_up'))
|
|
||||||
|
allowed_ctypes = ('', )
|
||||||
|
allowed_ctypes += get_ctypes('stairs', request.POST.get('stairs'))
|
||||||
|
allowed_ctypes += get_ctypes('escalator', request.POST.get('escalators'))
|
||||||
|
allowed_ctypes += get_ctypes('elevator', request.POST.get('elevators'))
|
||||||
|
|
||||||
|
route = graph.get_route(origin, destination, allowed_ctypes)
|
||||||
print(route)
|
print(route)
|
||||||
route = route.split()
|
route = route.split()
|
||||||
print(route)
|
print(route)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue