add missing api endpoints for descriptions and access restriction groups
This commit is contained in:
parent
a23be40cac
commit
303c4be485
4 changed files with 48 additions and 7 deletions
|
@ -8,8 +8,9 @@ from rest_framework.response import Response
|
|||
from rest_framework.routers import SimpleRouter
|
||||
|
||||
from c3nav.editor.api import ChangeSetViewSet, EditorViewSet
|
||||
from c3nav.mapdata.api import (AccessRestrictionViewSet, AreaViewSet, BuildingViewSet, ColumnViewSet, DoorViewSet,
|
||||
HoleViewSet, LevelViewSet, LineObstacleViewSet, LocationBySlugViewSet,
|
||||
from c3nav.mapdata.api import (AccessRestrictionGroupViewSet, AccessRestrictionViewSet, AreaViewSet, BuildingViewSet,
|
||||
ColumnViewSet, CrossDescriptionViewSet, DoorViewSet, HoleViewSet,
|
||||
LeaveDescriptionViewSet, LevelViewSet, LineObstacleViewSet, LocationBySlugViewSet,
|
||||
LocationGroupCategoryViewSet, LocationGroupViewSet, LocationViewSet, MapViewSet,
|
||||
ObstacleViewSet, POIViewSet, RampViewSet, SourceViewSet, SpaceViewSet, StairViewSet,
|
||||
UserViewSet)
|
||||
|
@ -29,8 +30,11 @@ router.register(r'obstacles', ObstacleViewSet)
|
|||
router.register(r'lineobstacles', LineObstacleViewSet)
|
||||
router.register(r'columns', ColumnViewSet)
|
||||
router.register(r'pois', POIViewSet)
|
||||
router.register(r'leavedescriptions', LeaveDescriptionViewSet)
|
||||
router.register(r'crossdescriptions', CrossDescriptionViewSet)
|
||||
router.register(r'sources', SourceViewSet)
|
||||
router.register(r'accessrestrictions', AccessRestrictionViewSet)
|
||||
router.register(r'accessrestrictiongroups', AccessRestrictionGroupViewSet)
|
||||
|
||||
router.register(r'locations', LocationViewSet)
|
||||
router.register(r'locations/by_slug', LocationBySlugViewSet, base_name='location-by-slug')
|
||||
|
|
|
@ -18,10 +18,10 @@ from rest_framework.response import Response
|
|||
from rest_framework.viewsets import GenericViewSet, ReadOnlyModelViewSet, ViewSet
|
||||
|
||||
from c3nav.mapdata.models import AccessRestriction, Building, Door, Hole, LocationGroup, MapUpdate, Source, Space
|
||||
from c3nav.mapdata.models.access import AccessPermission
|
||||
from c3nav.mapdata.models.access import AccessPermission, AccessRestrictionGroup
|
||||
from c3nav.mapdata.models.geometry.level import LevelGeometryMixin
|
||||
from c3nav.mapdata.models.geometry.space import (POI, Area, Column, LineObstacle, Obstacle, Ramp, SpaceGeometryMixin,
|
||||
Stair)
|
||||
from c3nav.mapdata.models.geometry.space import (POI, Area, Column, CrossDescription, LeaveDescription, LineObstacle,
|
||||
Obstacle, Ramp, SpaceGeometryMixin, Stair)
|
||||
from c3nav.mapdata.models.level import Level
|
||||
from c3nav.mapdata.models.locations import (Location, LocationGroupCategory, LocationRedirect, LocationSlug,
|
||||
SpecificLocation)
|
||||
|
@ -36,6 +36,8 @@ def optimize_query(qs):
|
|||
if issubclass(qs.model, SpecificLocation):
|
||||
base_qs = LocationGroup.objects.select_related('category')
|
||||
qs = qs.prefetch_related(Prefetch('groups', queryset=base_qs))
|
||||
if issubclass(qs.model, AccessRestriction):
|
||||
qs = qs.prefetch_related('groups')
|
||||
return qs
|
||||
|
||||
|
||||
|
@ -262,6 +264,14 @@ class POIViewSet(MapdataViewSet):
|
|||
queryset = POI.objects.all()
|
||||
|
||||
|
||||
class LeaveDescriptionViewSet(MapdataViewSet):
|
||||
queryset = LeaveDescription.objects.all()
|
||||
|
||||
|
||||
class CrossDescriptionViewSet(MapdataViewSet):
|
||||
queryset = CrossDescription.objects.all()
|
||||
|
||||
|
||||
class LocationGroupCategoryViewSet(MapdataViewSet):
|
||||
queryset = LocationGroupCategory.objects.all()
|
||||
|
||||
|
@ -390,6 +400,10 @@ class AccessRestrictionViewSet(MapdataViewSet):
|
|||
queryset = AccessRestriction.objects.all()
|
||||
|
||||
|
||||
class AccessRestrictionGroupViewSet(MapdataViewSet):
|
||||
queryset = AccessRestrictionGroup.objects.all()
|
||||
|
||||
|
||||
class UserViewSet(GenericViewSet):
|
||||
"""
|
||||
Get display information about the current user. This endpoint also sets the tile access cookie.
|
||||
|
|
|
@ -28,6 +28,11 @@ class AccessRestriction(TitledMixin, models.Model):
|
|||
verbose_name_plural = _('Access Restrictions')
|
||||
default_related_name = 'accessrestrictions'
|
||||
|
||||
def _serialize(self, **kwargs):
|
||||
result = super()._serialize(**kwargs)
|
||||
result['groups'] = tuple(group.pk for group in self.groups.all())
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def qs_for_request(cls, request):
|
||||
return cls.objects.filter(cls.q_for_request(request))
|
||||
|
|
|
@ -11,6 +11,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from shapely.geometry import CAP_STYLE, JOIN_STYLE, mapping
|
||||
|
||||
from c3nav.mapdata.fields import GeometryField, I18nField, JSONField
|
||||
from c3nav.mapdata.models.base import SerializableMixin
|
||||
from c3nav.mapdata.models.geometry.base import GeometryMixin
|
||||
from c3nav.mapdata.models.locations import SpecificLocation
|
||||
from c3nav.mapdata.utils.cache.changes import changed_geometries
|
||||
|
@ -247,7 +248,7 @@ class AltitudeMarker(SpaceGeometryMixin, models.Model):
|
|||
return '%s (%sm)' % (super().title, self.altitude)
|
||||
|
||||
|
||||
class LeaveDescription(models.Model):
|
||||
class LeaveDescription(SerializableMixin):
|
||||
"""
|
||||
A description for leaving a space to another space
|
||||
"""
|
||||
|
@ -264,12 +265,20 @@ class LeaveDescription(models.Model):
|
|||
('space', 'target_space')
|
||||
)
|
||||
|
||||
def _serialize(self, **kwargs):
|
||||
result = super()._serialize(**kwargs)
|
||||
result['space'] = self.space_id
|
||||
result['target_space'] = self.target_space_id
|
||||
result['description_i18n'] = self.description_i18n
|
||||
result['description'] = self.description
|
||||
return result
|
||||
|
||||
@cached_property
|
||||
def title(self):
|
||||
return self.target_space.title
|
||||
|
||||
|
||||
class CrossDescription(models.Model):
|
||||
class CrossDescription(SerializableMixin):
|
||||
"""
|
||||
A description for crossing a space from one space to another space
|
||||
"""
|
||||
|
@ -288,6 +297,15 @@ class CrossDescription(models.Model):
|
|||
('space', 'origin_space', 'target_space')
|
||||
)
|
||||
|
||||
def _serialize(self, **kwargs):
|
||||
result = super()._serialize(**kwargs)
|
||||
result['space'] = self.space_id
|
||||
result['origin_space'] = self.origin_space_id
|
||||
result['target_space'] = self.target_space_id
|
||||
result['description_i18n'] = self.description_i18n
|
||||
result['description'] = self.description
|
||||
return result
|
||||
|
||||
@cached_property
|
||||
def title(self):
|
||||
return '%s → %s' % (self.origin_space.title, self.target_space.title)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue