create LocationGroupCategory
This commit is contained in:
parent
52c64b0798
commit
4a58c1afab
4 changed files with 86 additions and 4 deletions
|
@ -9,8 +9,8 @@ from rest_framework.routers import SimpleRouter
|
||||||
|
|
||||||
from c3nav.editor.api import ChangeSetViewSet, EditorViewSet
|
from c3nav.editor.api import ChangeSetViewSet, EditorViewSet
|
||||||
from c3nav.mapdata.api import (AreaViewSet, BuildingViewSet, ColumnViewSet, DoorViewSet, HoleViewSet, LevelViewSet,
|
from c3nav.mapdata.api import (AreaViewSet, BuildingViewSet, ColumnViewSet, DoorViewSet, HoleViewSet, LevelViewSet,
|
||||||
LineObstacleViewSet, LocationGroupViewSet, LocationViewSet, ObstacleViewSet, POIViewSet,
|
LineObstacleViewSet, LocationGroupCategoryViewSet, LocationGroupViewSet, LocationViewSet,
|
||||||
SourceViewSet, SpaceViewSet, StairViewSet)
|
ObstacleViewSet, POIViewSet, SourceViewSet, SpaceViewSet, StairViewSet)
|
||||||
|
|
||||||
router = SimpleRouter()
|
router = SimpleRouter()
|
||||||
router.register(r'levels', LevelViewSet)
|
router.register(r'levels', LevelViewSet)
|
||||||
|
@ -27,6 +27,7 @@ router.register(r'pois', POIViewSet)
|
||||||
router.register(r'sources', SourceViewSet)
|
router.register(r'sources', SourceViewSet)
|
||||||
|
|
||||||
router.register(r'locations', LocationViewSet)
|
router.register(r'locations', LocationViewSet)
|
||||||
|
router.register(r'locationgroupcategories', LocationGroupCategoryViewSet)
|
||||||
router.register(r'locationgroups', LocationGroupViewSet)
|
router.register(r'locationgroups', LocationGroupViewSet)
|
||||||
|
|
||||||
router.register(r'editor', EditorViewSet, base_name='editor')
|
router.register(r'editor', EditorViewSet, base_name='editor')
|
||||||
|
|
|
@ -16,7 +16,8 @@ from c3nav.mapdata.models import Building, Door, Hole, LocationGroup, Source, Sp
|
||||||
from c3nav.mapdata.models.geometry.level import LevelGeometryMixin
|
from c3nav.mapdata.models.geometry.level import LevelGeometryMixin
|
||||||
from c3nav.mapdata.models.geometry.space import POI, Area, Column, LineObstacle, Obstacle, SpaceGeometryMixin, Stair
|
from c3nav.mapdata.models.geometry.space import POI, Area, Column, LineObstacle, Obstacle, SpaceGeometryMixin, Stair
|
||||||
from c3nav.mapdata.models.level import Level
|
from c3nav.mapdata.models.level import Level
|
||||||
from c3nav.mapdata.models.locations import Location, LocationRedirect, LocationSlug, SpecificLocation
|
from c3nav.mapdata.models.locations import (Location, LocationGroupCategory, LocationRedirect, LocationSlug,
|
||||||
|
SpecificLocation)
|
||||||
from c3nav.mapdata.utils.models import get_submodels
|
from c3nav.mapdata.utils.models import get_submodels
|
||||||
|
|
||||||
|
|
||||||
|
@ -138,6 +139,10 @@ class POIViewSet(MapdataViewSet):
|
||||||
queryset = POI.objects.all()
|
queryset = POI.objects.all()
|
||||||
|
|
||||||
|
|
||||||
|
class LocationGroupCategoryViewSet(MapdataViewSet):
|
||||||
|
queryset = LocationGroupCategory.objects.all()
|
||||||
|
|
||||||
|
|
||||||
class LocationGroupViewSet(MapdataViewSet):
|
class LocationGroupViewSet(MapdataViewSet):
|
||||||
queryset = LocationGroup.objects.all()
|
queryset = LocationGroup.objects.all()
|
||||||
|
|
||||||
|
|
56
src/c3nav/mapdata/migrations/0019_location_group_category.py
Normal file
56
src/c3nav/mapdata/migrations/0019_location_group_category.py
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.2 on 2017-07-10 11:39
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import c3nav.mapdata.fields
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
def create_location_group_category(apps, schema_editor):
|
||||||
|
LocationGroupCategory = apps.get_model('mapdata', 'LocationGroupCategory')
|
||||||
|
category = LocationGroupCategory.objects.create(name='groups', titles={
|
||||||
|
'en': 'Location Groups',
|
||||||
|
'de': 'Ortgruppen',
|
||||||
|
})
|
||||||
|
LocationGroup = apps.get_model('mapdata', 'LocationGroup')
|
||||||
|
LocationGroup.objects.update(category=category)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('mapdata', '0018_auto_20170708_1752'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='LocationGroupCategory',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('titles', c3nav.mapdata.fields.JSONField(default={})),
|
||||||
|
('name', models.SlugField(unique=True, verbose_name='Name')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Location Group Category',
|
||||||
|
'verbose_name_plural': 'Location Group Categories',
|
||||||
|
'default_related_name': 'locationgroupcategories',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='locationslug',
|
||||||
|
options={'verbose_name': 'Location with Slug', 'verbose_name_plural': 'Location with Slug'},
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='locationgroup',
|
||||||
|
name='category',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='groups', to='mapdata.LocationGroupCategory', verbose_name='Location Group Category'),
|
||||||
|
),
|
||||||
|
migrations.RunPython(create_location_group_category, lambda: None),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='locationgroup',
|
||||||
|
name='category',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='groups',
|
||||||
|
to='mapdata.LocationGroupCategory', verbose_name='Location Group Category'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -148,7 +148,25 @@ class SpecificLocation(Location, models.Model):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
class LocationGroupCategory(TitledMixin, models.Model):
|
||||||
|
name = models.SlugField(_('Name'), unique=True, max_length=50)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = _('Location Group Category')
|
||||||
|
verbose_name_plural = _('Location Group Categories')
|
||||||
|
default_related_name = 'locationgroupcategories'
|
||||||
|
|
||||||
|
def _serialize(self, **kwargs):
|
||||||
|
result = super()._serialize(**kwargs)
|
||||||
|
result['name'] = self.name
|
||||||
|
result.move_to_end('name', last=False)
|
||||||
|
result.move_to_end('id', last=False)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
class LocationGroup(Location, models.Model):
|
class LocationGroup(Location, models.Model):
|
||||||
|
category = models.ForeignKey(LocationGroupCategory, related_name='groups', on_delete=models.PROTECT,
|
||||||
|
verbose_name=_('Location Group Category'))
|
||||||
compiled_room = models.BooleanField(default=False, verbose_name=_('is a compiled room'))
|
compiled_room = models.BooleanField(default=False, verbose_name=_('is a compiled room'))
|
||||||
compiled_area = models.BooleanField(default=False, verbose_name=_('is a compiled area'))
|
compiled_area = models.BooleanField(default=False, verbose_name=_('is a compiled area'))
|
||||||
|
|
||||||
|
@ -159,6 +177,7 @@ class LocationGroup(Location, models.Model):
|
||||||
|
|
||||||
def _serialize(self, **kwargs):
|
def _serialize(self, **kwargs):
|
||||||
result = super()._serialize(**kwargs)
|
result = super()._serialize(**kwargs)
|
||||||
|
result['category'] = self.category_id
|
||||||
result['compiled_room'] = self.compiled_room
|
result['compiled_room'] = self.compiled_room
|
||||||
result['compiled_area'] = self.compiled_area
|
result['compiled_area'] = self.compiled_area
|
||||||
return result
|
return result
|
||||||
|
@ -182,7 +201,8 @@ class LocationGroup(Location, models.Model):
|
||||||
|
|
||||||
|
|
||||||
class LocationRedirect(LocationSlug):
|
class LocationRedirect(LocationSlug):
|
||||||
target = models.ForeignKey(LocationSlug, verbose_name=_('target'), related_name='redirects')
|
target = models.ForeignKey(LocationSlug, related_name='redirects', on_delete=models.CASCADE,
|
||||||
|
verbose_name=_('target'))
|
||||||
|
|
||||||
def _serialize(self, with_type=True, **kwargs):
|
def _serialize(self, with_type=True, **kwargs):
|
||||||
result = super()._serialize(with_type=with_type, **kwargs)
|
result = super()._serialize(with_type=with_type, **kwargs)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue