2017-05-06 17:24:09 +02:00
|
|
|
from django.db import models
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
2017-05-08 16:05:44 +02:00
|
|
|
from c3nav.mapdata.fields import GeometryField
|
2017-07-13 23:49:00 +02:00
|
|
|
from c3nav.mapdata.models.access import AccessRestrictionMixin
|
2017-05-08 16:40:22 +02:00
|
|
|
from c3nav.mapdata.models.geometry.base import GeometryMixin
|
2017-05-10 18:03:57 +02:00
|
|
|
from c3nav.mapdata.models.locations import SpecificLocation
|
2017-05-06 17:24:09 +02:00
|
|
|
|
|
|
|
|
2017-06-11 14:43:14 +02:00
|
|
|
class LevelGeometryMixin(GeometryMixin):
|
|
|
|
level = models.ForeignKey('mapdata.Level', on_delete=models.CASCADE, verbose_name=_('level'))
|
2017-05-09 12:50:32 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
2017-06-16 18:38:41 +02:00
|
|
|
def get_geojson_properties(self, *args, instance=None, **kwargs) -> dict:
|
|
|
|
result = super().get_geojson_properties(*args, **kwargs)
|
2017-06-11 14:43:14 +02:00
|
|
|
result['level'] = self.level_id
|
2017-05-21 23:39:26 +02:00
|
|
|
if hasattr(self, 'get_color'):
|
2017-06-16 18:38:41 +02:00
|
|
|
color = self.get_color(instance=instance)
|
2017-05-21 23:39:26 +02:00
|
|
|
if color:
|
|
|
|
result['color'] = color
|
2017-06-11 13:26:35 +02:00
|
|
|
if hasattr(self, 'opacity'):
|
|
|
|
result['opacity'] = self.opacity
|
2017-05-11 19:36:49 +02:00
|
|
|
return result
|
|
|
|
|
2017-06-11 14:43:14 +02:00
|
|
|
def _serialize(self, level=True, **kwargs):
|
2017-05-11 19:36:49 +02:00
|
|
|
result = super()._serialize(**kwargs)
|
2017-06-11 14:43:14 +02:00
|
|
|
if level:
|
|
|
|
result['level'] = self.level_id
|
2017-05-06 17:24:09 +02:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
2017-06-11 14:43:14 +02:00
|
|
|
class Building(LevelGeometryMixin, models.Model):
|
2017-05-06 17:24:09 +02:00
|
|
|
"""
|
|
|
|
The outline of a building on a specific level
|
|
|
|
"""
|
2017-05-08 16:05:44 +02:00
|
|
|
geometry = GeometryField('polygon')
|
2017-05-06 17:24:09 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _('Building')
|
|
|
|
verbose_name_plural = _('Buildings')
|
|
|
|
default_related_name = 'buildings'
|
|
|
|
|
|
|
|
|
2017-06-11 14:43:14 +02:00
|
|
|
class Space(SpecificLocation, LevelGeometryMixin, models.Model):
|
2017-05-06 17:24:09 +02:00
|
|
|
"""
|
2017-06-11 14:43:14 +02:00
|
|
|
An accessible space. Shouldn't overlap with spaces on the same level.
|
2017-05-06 17:24:09 +02:00
|
|
|
"""
|
2017-05-09 09:36:08 +02:00
|
|
|
geometry = GeometryField('polygon')
|
2017-06-11 13:18:25 +02:00
|
|
|
outside = models.BooleanField(default=False, verbose_name=_('only outside of building'))
|
2017-05-06 17:24:09 +02:00
|
|
|
|
|
|
|
class Meta:
|
2017-05-09 13:48:55 +02:00
|
|
|
verbose_name = _('Space')
|
|
|
|
verbose_name_plural = _('Spaces')
|
|
|
|
default_related_name = 'spaces'
|
2017-05-06 17:24:09 +02:00
|
|
|
|
|
|
|
|
2017-07-13 23:49:00 +02:00
|
|
|
class Door(AccessRestrictionMixin, LevelGeometryMixin, models.Model):
|
2017-05-06 17:24:09 +02:00
|
|
|
"""
|
2017-05-09 13:48:55 +02:00
|
|
|
A connection between two spaces
|
2017-05-06 17:24:09 +02:00
|
|
|
"""
|
2017-05-08 16:05:44 +02:00
|
|
|
geometry = GeometryField('polygon')
|
2017-05-06 17:24:09 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _('Door')
|
|
|
|
verbose_name_plural = _('Doors')
|
|
|
|
default_related_name = 'doors'
|