delete AreaLocation

This commit is contained in:
Laura Klünder 2017-05-10 21:31:54 +02:00
parent 69ac1b74c6
commit 67f2bcdf0e
11 changed files with 32 additions and 105 deletions

View file

@ -2,7 +2,6 @@ from django.forms import ModelForm, MultipleChoiceField
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from c3nav.access.models import AccessToken, AccessUser from c3nav.access.models import AccessToken, AccessUser
from c3nav.mapdata.models import AreaLocation
def get_permissions_field(request): def get_permissions_field(request):

View file

@ -10,8 +10,6 @@ from django.utils.crypto import get_random_string
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from c3nav.mapdata.models import AreaLocation
class AccessOperator(models.Model): class AccessOperator(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='operator') user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='operator')

View file

@ -4,7 +4,7 @@ from django.http.response import Http404
from django.shortcuts import get_object_or_404, redirect, render from django.shortcuts import get_object_or_404, redirect, render
from c3nav.access.apply import can_access, filter_queryset_by_access from c3nav.access.apply import can_access, filter_queryset_by_access
from c3nav.mapdata.models import AreaLocation, Section from c3nav.mapdata.models import Section
from c3nav.mapdata.models.base import EDITOR_FORM_MODELS from c3nav.mapdata.models.base import EDITOR_FORM_MODELS

View file

@ -10,7 +10,7 @@ from rest_framework.viewsets import ReadOnlyModelViewSet, ViewSet
from c3nav.access.apply import filter_arealocations_by_access, filter_queryset_by_access from c3nav.access.apply import filter_arealocations_by_access, filter_queryset_by_access
from c3nav.mapdata.lastupdate import get_last_mapdata_update from c3nav.mapdata.lastupdate import get_last_mapdata_update
from c3nav.mapdata.models import AreaLocation, LocationGroup, Source from c3nav.mapdata.models import LocationGroup, Source
from c3nav.mapdata.models.geometry.base import GEOMETRY_MODELS from c3nav.mapdata.models.geometry.base import GEOMETRY_MODELS
from c3nav.mapdata.models.geometry.space import Stair from c3nav.mapdata.models.geometry.space import Stair
from c3nav.mapdata.models.section import Section from c3nav.mapdata.models.section import Section
@ -53,7 +53,7 @@ class GeometryViewSet(ViewSet):
return self._list(request, types=types, add_cache_key=cache_key) return self._list(request, types=types, add_cache_key=cache_key)
@staticmethod @staticmethod
def compare_by_location_type(x: AreaLocation, y: AreaLocation): def compare_by_location_type(x, y):
return AreaLocation.LOCATION_TYPES.index(x.location_type) - AreaLocation.LOCATION_TYPES.index(y.location_type) return AreaLocation.LOCATION_TYPES.index(x.location_type) - AreaLocation.LOCATION_TYPES.index(y.location_type)
@cache_mapdata_api_response() @cache_mapdata_api_response()

View file

@ -2,8 +2,6 @@ from collections import OrderedDict
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from c3nav.mapdata.models import AreaLocation
def get_default_include_avoid(): def get_default_include_avoid():
include = set() include = set()

View file

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-05-10 19:31
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('mapdata', '0089_assign_location_area'),
]
operations = [
migrations.RemoveField(
model_name='arealocation',
name='groups',
),
migrations.RemoveField(
model_name='arealocation',
name='section',
),
migrations.DeleteModel(
name='AreaLocation',
),
]

View file

@ -2,4 +2,4 @@ from .section import Section # noqa
from .source import Source # noqa from .source import Source # noqa
from c3nav.mapdata.models.geometry.section import Building, Space, Hole, Door # 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 c3nav.mapdata.models.geometry.space import Area, Stair, Obstacle, LineObstacle # noqa
from .locations import AreaLocation, LocationGroup # noqa from .locations import Location, LocationGroup # noqa

View file

@ -124,99 +124,6 @@ class LocationGroup(Location, EditorFormMixin, models.Model):
return result 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): class PointLocation(LegacyLocation):
def __init__(self, section: 'Section', x: int, y: int, request): def __init__(self, section: 'Section', x: int, y: int, request):
self.section = section self.section = section

View file

@ -3,7 +3,7 @@ import re
from django.db.models import Q from django.db.models import Q
from c3nav.access.apply import filter_arealocations_by_access, filter_queryset_by_access from c3nav.access.apply import filter_arealocations_by_access, filter_queryset_by_access
from c3nav.mapdata.models import AreaLocation, LocationGroup from c3nav.mapdata.models import LocationGroup
from c3nav.mapdata.models.locations import PointLocation from c3nav.mapdata.models.locations import PointLocation
from c3nav.mapdata.utils.cache import get_sections_cached from c3nav.mapdata.utils.cache import get_sections_cached

View file

@ -8,7 +8,7 @@ from django.conf import settings
from scipy.sparse.csgraph._shortest_path import shortest_path from scipy.sparse.csgraph._shortest_path import shortest_path
from scipy.sparse.csgraph._tools import csgraph_from_dense from scipy.sparse.csgraph._tools import csgraph_from_dense
from c3nav.mapdata.models.locations import AreaLocation, Location, LocationGroup, PointLocation from c3nav.mapdata.models.locations import Location, LocationGroup, PointLocation
from c3nav.mapdata.models.section import Section from c3nav.mapdata.models.section import Section
from c3nav.routing.connection import GraphConnection from c3nav.routing.connection import GraphConnection
from c3nav.routing.exceptions import AlreadyThere, NoRouteFound, NotYetRoutable from c3nav.routing.exceptions import AlreadyThere, NoRouteFound, NotYetRoutable

View file

@ -4,7 +4,6 @@ from collections import OrderedDict
import numpy as np import numpy as np
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from c3nav.mapdata.models import AreaLocation
from c3nav.mapdata.utils.misc import get_dimensions from c3nav.mapdata.utils.misc import get_dimensions