delete AreaLocation
This commit is contained in:
parent
69ac1b74c6
commit
67f2bcdf0e
11 changed files with 32 additions and 105 deletions
|
@ -2,4 +2,4 @@ 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 .locations import AreaLocation, LocationGroup # noqa
|
||||
from .locations import Location, LocationGroup # noqa
|
||||
|
|
|
@ -124,99 +124,6 @@ class LocationGroup(Location, EditorFormMixin, models.Model):
|
|||
return result
|
||||
|
||||
|
||||
class AreaLocation(models.Model):
|
||||
LOCATION_TYPES = (
|
||||
('level', _('Level')),
|
||||
('area', _('General Area')),
|
||||
('room', _('Room')),
|
||||
('roomsegment', _('Room Segment')),
|
||||
('poi', _('Point of Interest')),
|
||||
)
|
||||
LOCATION_TYPES_ORDER = tuple(name for name, title in LOCATION_TYPES)
|
||||
ROUTING_INCLUSIONS = (
|
||||
('default', _('Default, include it is unlocked')),
|
||||
('allow_avoid', _('Included, but allow excluding')),
|
||||
('allow_include', _('Avoided, but allow including')),
|
||||
('needs_permission', _('Excluded, needs permission to include')),
|
||||
)
|
||||
|
||||
section = models.ForeignKey('mapdata.Section', on_delete=models.CASCADE, verbose_name=_('section'))
|
||||
geometry = GeometryField('polygon')
|
||||
slug = models.SlugField(_('Name'), unique=True, max_length=50)
|
||||
location_type = models.CharField(max_length=20, choices=LOCATION_TYPES, verbose_name=_('Location Type'))
|
||||
titles = JSONField()
|
||||
groups = models.ManyToManyField(LocationGroup, verbose_name=_('Location Groups'), blank=True)
|
||||
public = models.BooleanField(verbose_name=_('public'))
|
||||
|
||||
can_search = models.BooleanField(default=True, verbose_name=_('can be searched'))
|
||||
can_describe = models.BooleanField(default=True, verbose_name=_('can be used to describe a position'))
|
||||
color = models.CharField(null=True, blank=True, max_length=16, verbose_name=_('background color'),
|
||||
help_text=_('if set, has to be a valid color for svg images'))
|
||||
routing_inclusion = models.CharField(max_length=20, choices=ROUTING_INCLUSIONS, default='default',
|
||||
verbose_name=_('Routing Inclusion'))
|
||||
bssids = models.TextField(blank=True, validators=[validate_bssid_lines], verbose_name=_('BSSIDs'))
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Area Location')
|
||||
verbose_name_plural = _('Area Locations')
|
||||
default_related_name = 'arealocations'
|
||||
|
||||
@cached_property
|
||||
def location_id(self):
|
||||
return self.slug
|
||||
|
||||
def get_in_areas(self):
|
||||
last_update = get_last_mapdata_update()
|
||||
if last_update is None:
|
||||
return self._get_in_areas()
|
||||
|
||||
cache_key = 'c3nav__mapdata__location__in_areas__'+last_update.isoformat()+'__'+str(self.id),
|
||||
in_areas = cache.get(cache_key)
|
||||
if not in_areas:
|
||||
in_areas = self._get_in_areas()
|
||||
cache.set(cache_key, in_areas, 900)
|
||||
|
||||
return in_areas
|
||||
|
||||
def _get_in_areas(self):
|
||||
my_area = self.geometry.area
|
||||
|
||||
in_areas = []
|
||||
area_location_i = self.get_sort_key(self)
|
||||
for location_type in reversed(self.LOCATION_TYPES_ORDER[:area_location_i]):
|
||||
for arealocation in AreaLocation.objects.filter(location_type=location_type, section=self.section):
|
||||
intersection_area = arealocation.geometry.intersection(self.geometry).area
|
||||
if intersection_area and intersection_area / my_area > 0.99:
|
||||
in_areas.append(arealocation)
|
||||
|
||||
return in_areas
|
||||
|
||||
@property
|
||||
def subtitle(self):
|
||||
return self.get_subtitle()
|
||||
|
||||
@property
|
||||
def subtitle_without_type(self):
|
||||
return self.get_subtitle()
|
||||
|
||||
def get_subtitle(self):
|
||||
items = []
|
||||
items += [group.title for group in self.groups.filter(can_describe=True)]
|
||||
items += [area.title for area in self.get_in_areas() if area.can_describe]
|
||||
return ', '.join(items)
|
||||
|
||||
@classmethod
|
||||
def get_sort_key(cls, arealocation):
|
||||
return cls.LOCATION_TYPES_ORDER.index(arealocation.location_type)
|
||||
|
||||
def get_geojson_properties(self):
|
||||
result = super().get_geojson_properties()
|
||||
return result
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
|
||||
class PointLocation(LegacyLocation):
|
||||
def __init__(self, section: 'Section', x: int, y: int, request):
|
||||
self.section = section
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue