improve state logic in map_index

This commit is contained in:
Laura Klünder 2017-10-31 15:37:19 +01:00
parent 91bf8b9652
commit 9787d915f4
2 changed files with 9 additions and 8 deletions

View file

@ -5,8 +5,7 @@ from c3nav.site.views import map_index
pos = r'(@(?P<level>\d+),(?P<x>\d+(\.\d+)?),(?P<y>\d+(\.\d+)?),(?P<zoom>\d+(\.\d+)?))?'
urlpatterns = [
url(r'^r/(?P<origin>[a-z0-9-_:]+)?/(?P<destination>[a-z0-9-_:]+)?/%s$' % pos,
map_index, name='site.routing', kwargs={'routing': True}),
url(r'^l/(?P<destination>[a-z0-9-_:]+)/%s$' % pos, map_index, name='site.location'),
url(r'^r/(?P<origin>([a-z0-9-_:]+)?)/(?P<destination>([a-z0-9-_:]+)?)/%s$' % pos, map_index, name='site.index'),
url(r'^l/(?P<destination>[a-z0-9-_:]+)/%s$' % pos, map_index, name='site.index'),
url(r'^%s$' % pos, map_index, name='site.index')
]

View file

@ -83,19 +83,21 @@ def check_location(location: Optional[str], request) -> Optional[SpecificLocatio
return location
def map_index(request, routing=False, origin=None, destination=None, level=None, x=None, y=None, zoom=None):
def map_index(request, origin=None, destination=None, level=None, x=None, y=None, zoom=None):
levels = Level.qs_for_request(request).filter(on_top_of_id__isnull=True)
origin = check_location(origin, request)
destination = check_location(destination, request)
origin_slug, destination_slug = origin, destination
origin = check_location(origin or None, request)
destination = check_location(destination or None, request)
state = {
'routing': routing,
'routing': origin_slug is not None,
'origin': (origin.serialize(detailed=False, simple_geometry=True, geometry=False)
if origin else None),
'destination': (destination.serialize(detailed=False, simple_geometry=True, geometry=False)
if destination else None),
'sidebar': bool(routing or destination),
'sidebar': destination_slug is not None,
}
if level is not None:
state.update({