add AreaLocation.bssids
This commit is contained in:
parent
45b5e82d22
commit
b33e9fe3eb
4 changed files with 33 additions and 2 deletions
|
@ -109,7 +109,7 @@ class MapitemFormMixin(ModelForm):
|
|||
def create_editor_form(mapitemtype):
|
||||
possible_fields = ['name', 'package', 'altitude', 'level', 'intermediate', 'levels', 'geometry', 'direction',
|
||||
'elevator', 'button', 'crop_to_level', 'width', 'groups', 'override_altitude', 'color',
|
||||
'location_type', 'can_search', 'can_describe', 'routing_inclusion', 'compiled_room']
|
||||
'location_type', 'can_search', 'can_describe', 'routing_inclusion', 'compiled_room', 'bssids']
|
||||
existing_fields = [field.name for field in mapitemtype._meta.get_fields() if field.name in possible_fields]
|
||||
|
||||
class EditorForm(MapitemFormMixin, ModelForm):
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import json
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import RegexValidator
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from shapely import validation
|
||||
from shapely.geometry import mapping, shape
|
||||
from shapely.geometry.base import BaseGeometry
|
||||
|
@ -9,6 +11,9 @@ from shapely.geometry.base import BaseGeometry
|
|||
from c3nav.mapdata.utils.geometry import clean_geometry
|
||||
from c3nav.mapdata.utils.json import format_geojson
|
||||
|
||||
validate_bssid_lines = RegexValidator(regex=r'^([0-9a-f](:[0-9a-f]){5}(\n[0-9a-f](:[0-9a-f]){5})*)?$',
|
||||
message=_('please enter a newline seperated lowercase list of BSSIDs'))
|
||||
|
||||
|
||||
def validate_geometry(geometry):
|
||||
if not isinstance(geometry, BaseGeometry):
|
||||
|
|
20
src/c3nav/mapdata/migrations/0036_arealocation_bssids.py
Normal file
20
src/c3nav/mapdata/migrations/0036_arealocation_bssids.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.4 on 2016-12-27 17:54
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('mapdata', '0035_auto_20161226_1154'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='arealocation',
|
||||
name='bssids',
|
||||
field=models.TextField(blank=True, help_text='newline separated', verbose_name='BSSIDs'),
|
||||
),
|
||||
]
|
|
@ -7,7 +7,7 @@ from django.utils.functional import cached_property
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ungettext_lazy
|
||||
|
||||
from c3nav.mapdata.fields import JSONField
|
||||
from c3nav.mapdata.fields import JSONField, validate_bssid_lines
|
||||
from c3nav.mapdata.lastupdate import get_last_mapdata_update
|
||||
from c3nav.mapdata.models import Level
|
||||
from c3nav.mapdata.models.base import MapItem
|
||||
|
@ -192,6 +192,7 @@ class AreaLocation(LocationModelMixin, GeometryMapItemWithLevel):
|
|||
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'))
|
||||
|
||||
geomtype = 'polygon'
|
||||
|
||||
|
@ -271,6 +272,9 @@ class AreaLocation(LocationModelMixin, GeometryMapItemWithLevel):
|
|||
raise ValueError('Invalid routing inclusion')
|
||||
kwargs['routing_inclusion'] = routing_inclusion
|
||||
|
||||
kwargs['bssids'] = data.get('bssids', '')
|
||||
validate_bssid_lines(kwargs['bssids'])
|
||||
|
||||
return kwargs
|
||||
|
||||
def get_geojson_properties(self):
|
||||
|
@ -285,6 +289,8 @@ class AreaLocation(LocationModelMixin, GeometryMapItemWithLevel):
|
|||
result['groups'] = sorted(self.groups.all().order_by('name').values_list('name', flat=True))
|
||||
result['location_type'] = self.location_type
|
||||
result['routing_inclusion'] = self.routing_inclusion
|
||||
if self.bssids:
|
||||
result['bssids'] = self.bssids
|
||||
result.move_to_end('geometry')
|
||||
return result
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue