new altitude modeling

This commit is contained in:
Laura Klünder 2017-08-05 11:56:29 +02:00
parent a6e00fa015
commit 6930e1bb7c
8 changed files with 102 additions and 9 deletions

View file

@ -66,3 +66,16 @@ class Door(AccessRestrictionMixin, LevelGeometryMixin, models.Model):
verbose_name = _('Door')
verbose_name_plural = _('Doors')
default_related_name = 'doors'
class AltitudeArea(LevelGeometryMixin, models.Model):
"""
An altitude area
"""
geometry = GeometryField('polygon')
altitude = models.DecimalField(_('altitude'), null=False, max_digits=6, decimal_places=2)
class Meta:
verbose_name = _('Altitude Area')
verbose_name_plural = _('Altitude Areas')
default_related_name = 'altitudeareas'

View file

@ -162,3 +162,16 @@ class Hole(SpaceGeometryMixin, models.Model):
verbose_name = _('Hole')
verbose_name_plural = _('Holes')
default_related_name = 'holes'
class AltitudeMarker(SpaceGeometryMixin, models.Model):
"""
An altitude marker
"""
geometry = GeometryField('point')
altitude = models.DecimalField(_('altitude'), null=False, max_digits=6, decimal_places=2)
class Meta:
verbose_name = _('Altitude Marker')
verbose_name_plural = _('Altitude Markers')
default_related_name = 'altitudemarkers'

View file

@ -16,7 +16,7 @@ class Level(SpecificLocation, models.Model):
"""
A map level
"""
altitude = models.DecimalField(_('level altitude'), null=False, unique=True, max_digits=6, decimal_places=2)
ordering = models.DecimalField(_('ordering'), null=False, unique=True, max_digits=6, decimal_places=2)
on_top_of = models.ForeignKey('mapdata.Level', null=True, on_delete=models.CASCADE,
related_name='levels_on_top', verbose_name=_('on top of'))
@ -24,7 +24,7 @@ class Level(SpecificLocation, models.Model):
verbose_name = _('Level')
verbose_name_plural = _('Levels')
default_related_name = 'levels'
ordering = ['altitude']
ordering = ['ordering']
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@ -34,14 +34,14 @@ class Level(SpecificLocation, models.Model):
raise TypeError
if level_model is None:
level_model = Level
return level_model.objects.filter(altitude__lt=self.altitude, on_top_of__isnull=True).order_by('-altitude')
return level_model.objects.filter(ordering__lt=self.ordering, on_top_of__isnull=True).order_by('-ordering')
def higher(self, level_model=None):
if self.on_top_of_id is not None:
raise TypeError
if level_model is None:
level_model = Level
return level_model.objects.filter(altitude__gt=self.altitude, on_top_of__isnull=True).order_by('altitude')
return level_model.objects.filter(ordering__gt=self.ordering, on_top_of__isnull=True).order_by('ordering')
@property
def sublevels(self):
@ -63,7 +63,7 @@ class Level(SpecificLocation, models.Model):
def _serialize(self, level=True, **kwargs):
result = super()._serialize(**kwargs)
result['altitude'] = float(str(self.altitude))
result['ordering'] = float(str(self.ordering))
return result
def _render_space_ground(self, svg, space):