remove old code
This commit is contained in:
parent
88bb6e6b06
commit
e0dc75c992
1 changed files with 3 additions and 178 deletions
|
@ -1,16 +1,14 @@
|
|||
# flake8: noqa
|
||||
import json
|
||||
from collections import OrderedDict
|
||||
from datetime import timedelta
|
||||
from typing import Mapping, Optional
|
||||
from typing import Optional
|
||||
|
||||
import qrcode
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.http import Http404, HttpResponse, JsonResponse
|
||||
from django.shortcuts import redirect, render
|
||||
from django.http import Http404, HttpResponse
|
||||
from django.shortcuts import render
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
|
||||
from c3nav.mapdata.models import Location, Source
|
||||
from c3nav.mapdata.models.access import AccessPermission
|
||||
|
@ -136,176 +134,3 @@ def map_index(request, mode=None, slug=None, slug2=None, details=None, level=Non
|
|||
'tile_cache_server': settings.TILE_CACHE_SERVER,
|
||||
}
|
||||
return render(request, 'site/map.html', ctx)
|
||||
|
||||
|
||||
def main(request, location=None, origin=None, destination=None):
|
||||
location = get_location_or_404(request, location)
|
||||
origin = get_location_or_404(request, origin)
|
||||
destination = get_location_or_404(request, destination)
|
||||
|
||||
mode = 'location' if not origin and not destination else 'route'
|
||||
|
||||
active_field = None
|
||||
if not origin and not destination:
|
||||
active_field = 'location'
|
||||
elif origin and not destination:
|
||||
active_field = 'destination'
|
||||
elif destination and not origin:
|
||||
active_field = 'origin'
|
||||
|
||||
ctx = {
|
||||
'location': location,
|
||||
'origin': origin,
|
||||
'destination': destination,
|
||||
'mode': mode,
|
||||
'active_field': active_field,
|
||||
|
||||
'full_access': request.c3nav_full_access,
|
||||
'access_list': request.c3nav_access_list,
|
||||
'visible_areas': get_visible_areas(request),
|
||||
}
|
||||
|
||||
width, height = get_dimensions()
|
||||
sections = tuple(section for id_, section in get_sections_cached().items())
|
||||
|
||||
ctx.update({
|
||||
'width': width,
|
||||
'height': height,
|
||||
'svg_width': int(width * 6),
|
||||
'svg_height': int(height * 6),
|
||||
'sections': sections,
|
||||
})
|
||||
|
||||
map_level = request.GET.get('map-level')
|
||||
if map_level in sections:
|
||||
ctx.update({
|
||||
'map_level': map_level
|
||||
})
|
||||
|
||||
if 'x' in request.POST and 'y' in request.POST:
|
||||
x = request.POST.get('x')
|
||||
y = request.POST.get('y')
|
||||
if x.isnumeric() and y.isnumeric():
|
||||
coords = 'c:%s:%d:%d' % (map_level, int(int(x)/6*100), height-int(int(y)/6*100))
|
||||
if active_field == 'origin':
|
||||
return redirect('site.route', origin=coords, destination=destination.location_id)
|
||||
elif active_field == 'destination':
|
||||
return redirect('site.route', origin=origin.location_id, destination=coords)
|
||||
elif active_field == 'location':
|
||||
return redirect('site.location', location=coords)
|
||||
|
||||
if active_field is not None:
|
||||
search_query = request.POST.get(active_field+'_search', '').strip() or None
|
||||
if search_query:
|
||||
results = search_location(request, search_query)
|
||||
|
||||
url = 'site.location' if active_field == 'location' else 'site.route'
|
||||
kwargs = {}
|
||||
if origin:
|
||||
kwargs['origin'] = origin.location_id
|
||||
if destination:
|
||||
kwargs['destination'] = destination.location_id
|
||||
for result in results:
|
||||
kwargs[active_field] = result.location_id
|
||||
result.url = reverse(url, kwargs=kwargs)
|
||||
|
||||
ctx.update({
|
||||
'search': active_field,
|
||||
'search_query': search_query,
|
||||
'search_results': results,
|
||||
})
|
||||
|
||||
# everything about settings
|
||||
include = ()
|
||||
avoid = ()
|
||||
stairs = 'yes'
|
||||
escalators = 'yes'
|
||||
elevators = 'yes'
|
||||
|
||||
save_settings = False
|
||||
if 'c3nav_settings' in request.COOKIES:
|
||||
cookie_value = request.COOKIES['c3nav_settings']
|
||||
|
||||
if isinstance(cookie_value, dict):
|
||||
stairs = cookie_value.get('stairs', stairs)
|
||||
escalators = cookie_value.get('escalators', escalators)
|
||||
elevators = cookie_value.get('elevators', elevators)
|
||||
|
||||
if isinstance(cookie_value.get('include'), list):
|
||||
include = cookie_value.get('include')
|
||||
|
||||
if isinstance(cookie_value.get('avoid'), list):
|
||||
avoid = cookie_value.get('avoid')
|
||||
|
||||
save_settings = True
|
||||
|
||||
if request.method == 'POST':
|
||||
stairs = request.POST.get('stairs', stairs)
|
||||
escalators = request.POST.get('escalators', escalators)
|
||||
elevators = request.POST.get('elevators', elevators)
|
||||
|
||||
include = request.POST.getlist('include')
|
||||
avoid = request.POST.getlist('avoid')
|
||||
|
||||
allowed_ctypes = ('', )
|
||||
allowed_ctypes += get_ctypes('stairs', request.POST.get('stairs', stairs))
|
||||
allowed_ctypes += get_ctypes('escalator', request.POST.get('escalators', escalators))
|
||||
allowed_ctypes += get_ctypes('elevator', request.POST.get('elevators', elevators))
|
||||
|
||||
stairs = reverse_ctypes(allowed_ctypes, 'stairs')
|
||||
escalators = reverse_ctypes(allowed_ctypes, 'escalator')
|
||||
elevators = reverse_ctypes(allowed_ctypes, 'elevator')
|
||||
|
||||
includables, avoidables = get_includables_avoidables(request)
|
||||
allow_nonpublic, include, avoid = parse_include_avoid(request, include, avoid)
|
||||
|
||||
if request.method == 'POST':
|
||||
save_settings = request.POST.get('save_settings', '') == '1'
|
||||
|
||||
ctx.update({
|
||||
'stairs': stairs,
|
||||
'escalators': escalators,
|
||||
'elevators': elevators,
|
||||
'excludables': avoidables.items(),
|
||||
'includables': includables.items(),
|
||||
'include': include,
|
||||
'avoid': avoid,
|
||||
'save_settings': save_settings,
|
||||
})
|
||||
|
||||
# routing
|
||||
if request.method == 'POST' and origin and destination:
|
||||
graph = Graph.load()
|
||||
|
||||
try:
|
||||
route = graph.get_route(origin, destination, allowed_ctypes, allow_nonpublic=allow_nonpublic,
|
||||
avoid=avoid-set(':public'), include=include-set(':nonpublic'))
|
||||
except NoRouteFound:
|
||||
ctx.update({'error': 'noroutefound'})
|
||||
except AlreadyThere:
|
||||
ctx.update({'error': 'alreadythere'})
|
||||
except NotYetRoutable:
|
||||
ctx.update({'error': 'notyetroutable'})
|
||||
else:
|
||||
route.describe(allowed_ctypes)
|
||||
ctx.update({'route': route})
|
||||
|
||||
if request.GET.get('format') == 'json':
|
||||
if 'error' in ctx:
|
||||
return JsonResponse({'error': ctx['error']})
|
||||
if 'route' in ctx:
|
||||
return JsonResponse({'route': ctx['route'].serialize()})
|
||||
|
||||
response = render(request, 'site/main.html', ctx)
|
||||
|
||||
if request.method == 'POST' and save_settings:
|
||||
cookie_value = {
|
||||
'stairs': stairs,
|
||||
'escalators': escalators,
|
||||
'elevators': elevators,
|
||||
'include': tuple(include),
|
||||
'avoid': tuple(avoid),
|
||||
}
|
||||
response.set_cookie('c3nav_settings', cookie_value, expires=timezone.now() + timedelta(days=30))
|
||||
|
||||
return response
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue