convert the model mixins to abstract models
This commit is contained in:
parent
65ccf1d92f
commit
a845f23cee
4 changed files with 18 additions and 10 deletions
|
@ -1,13 +1,17 @@
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
from django.utils.translation import get_language
|
from django.utils.translation import get_language
|
||||||
|
|
||||||
EDITOR_FORM_MODELS = OrderedDict()
|
EDITOR_FORM_MODELS = OrderedDict()
|
||||||
|
|
||||||
|
|
||||||
class EditorFormMixin:
|
class EditorFormMixin(models.Model):
|
||||||
EditorForm = None
|
EditorForm = None
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def title(self):
|
def title(self):
|
||||||
if not hasattr(self, 'titles'):
|
if not hasattr(self, 'titles'):
|
||||||
|
|
|
@ -2,6 +2,7 @@ from collections import OrderedDict
|
||||||
|
|
||||||
from shapely.geometry import Point, mapping
|
from shapely.geometry import Point, mapping
|
||||||
|
|
||||||
|
from c3nav.mapdata.fields import GeometryField
|
||||||
from c3nav.mapdata.models.base import EditorFormMixin
|
from c3nav.mapdata.models.base import EditorFormMixin
|
||||||
from c3nav.mapdata.utils.json import format_geojson
|
from c3nav.mapdata.utils.json import format_geojson
|
||||||
|
|
||||||
|
@ -12,6 +13,8 @@ class GeometryMixin(EditorFormMixin):
|
||||||
"""
|
"""
|
||||||
A map feature with a geometry
|
A map feature with a geometry
|
||||||
"""
|
"""
|
||||||
|
geometry = None
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,11 @@ SECTION_MODELS = OrderedDict()
|
||||||
|
|
||||||
|
|
||||||
class SectionGeometryMixin(GeometryMixin):
|
class SectionGeometryMixin(GeometryMixin):
|
||||||
|
section = models.ForeignKey('mapdata.Section', on_delete=models.CASCADE, verbose_name=_('section'))
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|
||||||
def get_geojson_properties(self):
|
def get_geojson_properties(self):
|
||||||
result = super().get_geojson_properties()
|
result = super().get_geojson_properties()
|
||||||
result['section'] = self.section.id
|
result['section'] = self.section.id
|
||||||
|
@ -20,7 +25,6 @@ class Building(SectionGeometryMixin, models.Model):
|
||||||
"""
|
"""
|
||||||
The outline of a building on a specific level
|
The outline of a building on a specific level
|
||||||
"""
|
"""
|
||||||
section = models.ForeignKey('mapdata.Section', on_delete=models.CASCADE, verbose_name=_('section'))
|
|
||||||
geometry = GeometryField('polygon')
|
geometry = GeometryField('polygon')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -45,8 +49,6 @@ class Space(SectionGeometryMixin, models.Model):
|
||||||
('upper', _('upper')),
|
('upper', _('upper')),
|
||||||
('lowerr', _('lower')),
|
('lowerr', _('lower')),
|
||||||
)
|
)
|
||||||
|
|
||||||
section = models.ForeignKey('mapdata.Section', on_delete=models.CASCADE, verbose_name=_('section'))
|
|
||||||
geometry = GeometryField('polygon')
|
geometry = GeometryField('polygon')
|
||||||
public = models.BooleanField(verbose_name=_('public'), default=True)
|
public = models.BooleanField(verbose_name=_('public'), default=True)
|
||||||
category = models.CharField(verbose_name=_('category'), choices=CATEGORIES, max_length=16)
|
category = models.CharField(verbose_name=_('category'), choices=CATEGORIES, max_length=16)
|
||||||
|
@ -69,7 +71,6 @@ class Door(SectionGeometryMixin, models.Model):
|
||||||
"""
|
"""
|
||||||
A connection between two rooms
|
A connection between two rooms
|
||||||
"""
|
"""
|
||||||
section = models.ForeignKey('mapdata.Section', on_delete=models.CASCADE, verbose_name=_('section'))
|
|
||||||
geometry = GeometryField('polygon')
|
geometry = GeometryField('polygon')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -82,7 +83,6 @@ class Hole(SectionGeometryMixin, models.Model):
|
||||||
"""
|
"""
|
||||||
A hole in the ground of a room, e.g. for stairs.
|
A hole in the ground of a room, e.g. for stairs.
|
||||||
"""
|
"""
|
||||||
section = models.ForeignKey('mapdata.Section', on_delete=models.CASCADE, verbose_name=_('section'))
|
|
||||||
geometry = GeometryField('polygon')
|
geometry = GeometryField('polygon')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -12,6 +12,11 @@ SPACE_MODELS = OrderedDict()
|
||||||
|
|
||||||
|
|
||||||
class SpaceGeometryMixin(GeometryMixin):
|
class SpaceGeometryMixin(GeometryMixin):
|
||||||
|
space = models.ForeignKey('mapdata.Space', on_delete=models.CASCADE, verbose_name=_('space'))
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|
||||||
def get_geojson_properties(self):
|
def get_geojson_properties(self):
|
||||||
result = super().get_geojson_properties()
|
result = super().get_geojson_properties()
|
||||||
result['space'] = self.space.id
|
result['space'] = self.space.id
|
||||||
|
@ -22,7 +27,6 @@ class StuffedArea(SpaceGeometryMixin, models.Model):
|
||||||
"""
|
"""
|
||||||
A slow area with many tables or similar. Avoid it from routing by slowing it a bit down
|
A slow area with many tables or similar. Avoid it from routing by slowing it a bit down
|
||||||
"""
|
"""
|
||||||
space = models.ForeignKey('mapdata.Space', on_delete=models.CASCADE, verbose_name=_('space'))
|
|
||||||
geometry = GeometryField('polygon')
|
geometry = GeometryField('polygon')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -35,7 +39,6 @@ class Stair(SpaceGeometryMixin, models.Model):
|
||||||
"""
|
"""
|
||||||
A stair
|
A stair
|
||||||
"""
|
"""
|
||||||
space = models.ForeignKey('mapdata.Space', on_delete=models.CASCADE, verbose_name=_('space'))
|
|
||||||
geometry = GeometryField('polyline')
|
geometry = GeometryField('polyline')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -70,7 +73,6 @@ class Obstacle(SpaceGeometryMixin, models.Model):
|
||||||
"""
|
"""
|
||||||
An obstacle
|
An obstacle
|
||||||
"""
|
"""
|
||||||
space = models.ForeignKey('mapdata.Space', on_delete=models.CASCADE, verbose_name=_('space'))
|
|
||||||
geometry = GeometryField('polygon')
|
geometry = GeometryField('polygon')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -83,7 +85,6 @@ class LineObstacle(SpaceGeometryMixin, models.Model):
|
||||||
"""
|
"""
|
||||||
An obstacle that is a line with a specific width
|
An obstacle that is a line with a specific width
|
||||||
"""
|
"""
|
||||||
space = models.ForeignKey('mapdata.Space', on_delete=models.CASCADE, verbose_name=_('space'))
|
|
||||||
geometry = GeometryField('polyline')
|
geometry = GeometryField('polyline')
|
||||||
width = models.DecimalField(_('obstacle width'), max_digits=4, decimal_places=2, default=0.15)
|
width = models.DecimalField(_('obstacle width'), max_digits=4, decimal_places=2, default=0.15)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue