move holes from sections to spaces

This commit is contained in:
Laura Klünder 2017-06-08 15:19:12 +02:00
parent 129be97a59
commit 98501dbf3a
9 changed files with 99 additions and 21 deletions

View file

@ -84,7 +84,7 @@ class DoorViewSet(MapdataViewSet):
class HoleViewSet(MapdataViewSet):
""" Add ?geometry=1 to get geometries, add ?section=<id> to filter by section. """
""" Add ?geometry=1 to get geometries, add ?space=<id> to filter by space. """
queryset = Hole.objects.all()

View file

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-06-08 13:01
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
def assign_hole_to_space(apps, schema_editor):
Hole = apps.get_model('mapdata', 'Hole')
Space = apps.get_model('mapdata', 'Space')
for hole in Hole.objects.filter():
space = max(hole.section.spaces.filter(level='normal'),
key=lambda s: s.geometry.intersection(hole.geometry).area)
hole.space = space
hole.save()
class Migration(migrations.Migration):
dependencies = [
('mapdata', '0006_remove_section_name'),
]
operations = [
migrations.AddField(
model_name='hole',
name='space',
field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, related_name='holes', to='mapdata.Space', verbose_name='space'),
preserve_default=False,
),
migrations.RunPython(assign_hole_to_space),
]

View file

@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-06-08 13:17
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('mapdata', '0007_assign_hole_space'),
]
operations = [
migrations.RemoveField(
model_name='hole',
name='section',
),
migrations.AlterField(
model_name='area',
name='color',
field=models.CharField(blank=True, max_length=16, null=True, verbose_name='background color'),
),
migrations.AlterField(
model_name='locationgroup',
name='color',
field=models.CharField(blank=True, max_length=16, null=True, verbose_name='background color'),
),
migrations.AlterField(
model_name='point',
name='color',
field=models.CharField(blank=True, max_length=16, null=True, verbose_name='background color'),
),
migrations.AlterField(
model_name='section',
name='color',
field=models.CharField(blank=True, max_length=16, null=True, verbose_name='background color'),
),
migrations.AlterField(
model_name='space',
name='color',
field=models.CharField(blank=True, max_length=16, null=True, verbose_name='background color'),
),
]

View file

@ -1,5 +1,5 @@
from .section import Section # noqa
from .source import Source # noqa
from c3nav.mapdata.models.geometry.section import Building, Space, Hole, Door # noqa
from c3nav.mapdata.models.geometry.space import Area, Stair, Obstacle, LineObstacle # noqa
from c3nav.mapdata.models.geometry.section import Building, Space, Door # noqa
from c3nav.mapdata.models.geometry.space import Area, Stair, Obstacle, LineObstacle, Hole # noqa
from .locations import Location, LocationSlug, LocationGroup # noqa

View file

@ -96,15 +96,3 @@ class Door(SectionGeometryMixin, models.Model):
verbose_name = _('Door')
verbose_name_plural = _('Doors')
default_related_name = 'doors'
class Hole(SectionGeometryMixin, models.Model):
"""
A hole in the ground of a section (all spaces with layer "normal" and buildings), e.g. for stairs.
"""
geometry = GeometryField('polygon')
class Meta:
verbose_name = _('Hole')
verbose_name_plural = _('Holes')
default_related_name = 'holes'

View file

@ -158,3 +158,15 @@ class Point(SpecificLocation, SpaceGeometryMixin, models.Model):
result['original_geometry'] = result['geometry']
result['geometry'] = format_geojson(mapping(self.buffered_geometry))
return result
class Hole(SpaceGeometryMixin, models.Model):
"""
A hole in the ground of a space, e.g. for stairs.
"""
geometry = GeometryField('polygon')
class Meta:
verbose_name = _('Hole')
verbose_name_plural = _('Holes')
default_related_name = 'holes'