dynamic location as a starting point
This commit is contained in:
parent
cca263c605
commit
1ecdc89a68
7 changed files with 63 additions and 13 deletions
|
@ -7,6 +7,7 @@ from rest_framework.viewsets import ViewSet
|
|||
|
||||
from c3nav.mapdata.api import api_stats_clean_location_value
|
||||
from c3nav.mapdata.models.access import AccessPermission
|
||||
from c3nav.mapdata.models.locations import Position
|
||||
from c3nav.mapdata.utils.cache.stats import increment_cache_key
|
||||
from c3nav.mapdata.utils.locations import visible_locations_for_request
|
||||
from c3nav.routing.exceptions import LocationUnreachable, NoRouteFound, NotYetRoutable
|
||||
|
@ -71,8 +72,8 @@ class RoutingViewSet(ViewSet):
|
|||
|
||||
return Response({
|
||||
'request': {
|
||||
'origin': form.cleaned_data['origin'].pk,
|
||||
'destination': form.cleaned_data['destination'].pk,
|
||||
'origin': self.get_request_pk(form.cleaned_data['origin']),
|
||||
'destination': self.get_request_pk(form.cleaned_data['destination']),
|
||||
},
|
||||
'options': options.serialize(),
|
||||
'report_issue_url': reverse('site.report_create', kwargs={
|
||||
|
@ -83,6 +84,9 @@ class RoutingViewSet(ViewSet):
|
|||
'result': route.serialize(locations=visible_locations_for_request(request)),
|
||||
})
|
||||
|
||||
def get_request_pk(self, location):
|
||||
return location.slug if isinstance(location, Position) else location.pk
|
||||
|
||||
@action(detail=False, methods=['get', 'post'])
|
||||
def options(self, request, *args, **kwargs):
|
||||
options = RouteOptions.get_for_request(request)
|
||||
|
|
|
@ -12,7 +12,10 @@ def describe_location(location, locations):
|
|||
final_location = locations.get(location.pk)
|
||||
if final_location is not None:
|
||||
location = final_location
|
||||
return location.serialize(include_type=True, detailed=False, simple_geometry=True)
|
||||
result = location.serialize(include_type=True, detailed=False, simple_geometry=True)
|
||||
if hasattr(location, 'serialize_position'):
|
||||
result.update(location.serialize_position())
|
||||
return result
|
||||
|
||||
|
||||
class Route:
|
||||
|
@ -170,7 +173,6 @@ class Route:
|
|||
|
||||
options_summary = ', '.join(str(s) for s in options_summary)
|
||||
|
||||
|
||||
return OrderedDict((
|
||||
('origin', describe_location(self.origin, locations)),
|
||||
('destination', describe_location(self.destination, locations)),
|
||||
|
|
|
@ -328,8 +328,8 @@ class Router:
|
|||
if poi.space_id not in restrictions.spaces and poi.access_restriction_id not in restrictions),
|
||||
))
|
||||
elif isinstance(location, (CustomLocation, CustomLocationProxyMixin)):
|
||||
if isinstance(location, CustomLocationProxyMixin):
|
||||
location = location.get_custom_location()
|
||||
if isinstance(location, CustomLocationProxyMixin) and not location.available:
|
||||
raise LocationUnreachable
|
||||
point = Point(location.x, location.y)
|
||||
location = RouterPoint(location)
|
||||
space = self.space_for_point(location.level.pk, point, restrictions)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue