replace Space.level with secondary sections on top of primary sections

This commit is contained in:
Laura Klünder 2017-06-10 14:58:13 +02:00
parent 9502e247d1
commit 9910b3ed83
7 changed files with 122 additions and 47 deletions

View file

@ -16,7 +16,6 @@ class SectionGeometryMixin(GeometryMixin):
def get_geojson_properties(self) -> dict:
result = super().get_geojson_properties()
result['layer'] = getattr(self, 'level', 'base')
if hasattr(self, 'get_color'):
color = self.get_color()
if color:
@ -44,13 +43,8 @@ class Building(SectionGeometryMixin, models.Model):
class Space(SpecificLocation, SectionGeometryMixin, models.Model):
"""
An accessible space. Shouldn't overlap with spaces on same secion and level.
An accessible space. Shouldn't overlap with spaces on same section.
"""
LEVELS = (
('normal', _('normal')),
('upper', _('upper')),
('lower', _('lower')),
)
CATEGORIES = (
('normal', _('normal')),
('stairs', _('stairs')),
@ -58,7 +52,6 @@ class Space(SpecificLocation, SectionGeometryMixin, models.Model):
('elevator', _('elevator')),
)
geometry = GeometryField('polygon')
level = models.CharField(verbose_name=_('level'), choices=LEVELS, default='normal', max_length=16)
category = models.CharField(verbose_name=_('category'), choices=CATEGORIES, default='normal', max_length=16)
outside = models.BooleanField(default=False, verbose_name=_('is outside of building'))
@ -71,7 +64,6 @@ class Space(SpecificLocation, SectionGeometryMixin, models.Model):
result = super()._serialize(**kwargs)
if space:
result['category'] = self.category
result['level'] = self.level
result['public'] = self.public
return result

View file

@ -14,6 +14,8 @@ class Section(SpecificLocation, EditorFormMixin, models.Model):
A map section like a level
"""
altitude = models.DecimalField(_('section altitude'), null=False, unique=True, max_digits=6, decimal_places=2)
on_top_of = models.ForeignKey('mapdata.Section', null=True, on_delete=models.CASCADE,
related_name='sections_on_top', verbose_name=_('on top of'))
class Meta:
verbose_name = _('Section')
@ -25,10 +27,14 @@ class Section(SpecificLocation, EditorFormMixin, models.Model):
super().__init__(*args, **kwargs)
def lower(self):
return Section.objects.filter(altitude__lt=self.altitude).order_by('altitude')
if self.on_top_of is not None:
raise TypeError
return Section.objects.filter(altitude__lt=self.altitude, on_top_of__isnull=True).order_by('-altitude')
def higher(self):
return Section.objects.filter(altitude__gt=self.altitude).order_by('altitude')
if self.on_top_of is not None:
raise TypeError
return Section.objects.filter(altitude__gt=self.altitude, on_top_of__isnull=True).order_by('altitude')
def _serialize(self, section=True, **kwargs):
result = super()._serialize(**kwargs)