remove intermediate levels
This commit is contained in:
parent
0d2663ca89
commit
baecf08aea
9 changed files with 146 additions and 51 deletions
|
@ -85,8 +85,7 @@ class MapitemFormMixin(ModelForm):
|
||||||
|
|
||||||
|
|
||||||
def create_editor_form(mapitemtype):
|
def create_editor_form(mapitemtype):
|
||||||
possible_fields = ['name', 'public', 'altitude', 'level', 'intermediate', 'levels', 'geometry', 'direction',
|
possible_fields = ['name', 'public', 'altitude', 'level', 'levels', 'geometry', 'width', 'groups', 'color',
|
||||||
'elevator', 'button', 'crop_to_level', 'width', 'groups', 'override_altitude', 'color',
|
|
||||||
'location_type', 'can_search', 'can_describe', 'routing_inclusion', 'compiled_room', 'bssids',
|
'location_type', 'can_search', 'can_describe', 'routing_inclusion', 'compiled_room', 'bssids',
|
||||||
'category', 'layer']
|
'category', 'layer']
|
||||||
existing_fields = [field.name for field in mapitemtype._meta.get_fields() if field.name in possible_fields]
|
existing_fields = [field.name for field in mapitemtype._meta.get_fields() if field.name in possible_fields]
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Generated by Django 1.10.4 on 2017-05-05 11:33
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('mapdata', '0049_auto_20170505_1125'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
]
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.4 on 2017-05-05 11:33
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def categorize_intermediate_areas(apps, schema_editor):
|
||||||
|
Level = apps.get_model('mapdata', 'Level')
|
||||||
|
for level in Level.objects.filter(intermediate=True):
|
||||||
|
for area in level.areas.filter(category=''):
|
||||||
|
area.category = 'escalator' if area.escalators.count() else 'stairs'
|
||||||
|
area.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('mapdata', '0049_auto_20170505_1125'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(categorize_intermediate_areas),
|
||||||
|
]
|
45
src/c3nav/mapdata/migrations/0051_move_intermediate_areas.py
Normal file
45
src/c3nav/mapdata/migrations/0051_move_intermediate_areas.py
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.4 on 2017-05-05 11:46
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def move_intermediate_areas(apps, schema_editor):
|
||||||
|
Level = apps.get_model('mapdata', 'Level')
|
||||||
|
for level in Level.objects.filter(intermediate=True):
|
||||||
|
lower_level = Level.objects.filter(altitude__lt=level.altitude).order_by('-altitude').first()
|
||||||
|
upper_level = Level.objects.filter(altitude__gt=level.altitude).order_by('altitude').first()
|
||||||
|
for area in level.areas.all():
|
||||||
|
area.level = lower_level
|
||||||
|
area.layer = 'upper'
|
||||||
|
area.save()
|
||||||
|
|
||||||
|
areaitems = []
|
||||||
|
for c in ('escalators', 'obstacles', 'lineobstacles', 'stairs', 'stuffedareas'):
|
||||||
|
areaitems.extend(getattr(area, c).all())
|
||||||
|
|
||||||
|
print(areaitems)
|
||||||
|
|
||||||
|
area.pk = None
|
||||||
|
area.name += '_'
|
||||||
|
area.level = upper_level
|
||||||
|
area.layer = 'lower'
|
||||||
|
area.save()
|
||||||
|
|
||||||
|
for areaitem in areaitems:
|
||||||
|
areaitem.pk = None
|
||||||
|
areaitem.name += '-_'
|
||||||
|
areaitem.area = area
|
||||||
|
areaitem.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('mapdata', '0050_categorize_intermediate_areas'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(move_intermediate_areas),
|
||||||
|
]
|
|
@ -0,0 +1,26 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.4 on 2017-05-05 12:09
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def delete_intermediate_levels(apps, schema_editor):
|
||||||
|
Level = apps.get_model('mapdata', 'Level')
|
||||||
|
print(Level.objects.filter(intermediate=True).count())
|
||||||
|
Level.objects.filter(intermediate=True).delete()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('mapdata', '0051_move_intermediate_areas'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(delete_intermediate_levels),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='level',
|
||||||
|
name='intermediate',
|
||||||
|
),
|
||||||
|
]
|
22
src/c3nav/mapdata/migrations/0053_auto_20170505_1212.py
Normal file
22
src/c3nav/mapdata/migrations/0053_auto_20170505_1212.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.4 on 2017-05-05 12:12
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('mapdata', '0052_remove_level_intermediate'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='escalator',
|
||||||
|
name='area',
|
||||||
|
),
|
||||||
|
migrations.DeleteModel(
|
||||||
|
name='Escalator',
|
||||||
|
),
|
||||||
|
]
|
|
@ -0,0 +1,25 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.4 on 2017-05-05 12:16
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def delete_crop_to_level_obstacles(apps, schema_editor):
|
||||||
|
Obstacle = apps.get_model('mapdata', 'Obstacle')
|
||||||
|
Obstacle.objects.filter(crop_to_level__isnull=False).delete()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('mapdata', '0053_auto_20170505_1212'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(delete_crop_to_level_obstacles),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='obstacle',
|
||||||
|
name='crop_to_level',
|
||||||
|
),
|
||||||
|
]
|
|
@ -79,6 +79,8 @@ class Area(LevelFeature):
|
||||||
|
|
||||||
def get_geojson_properties(self):
|
def get_geojson_properties(self):
|
||||||
result = super().get_geojson_properties()
|
result = super().get_geojson_properties()
|
||||||
|
result['category'] = self.category
|
||||||
|
result['layer'] = self.layer
|
||||||
result['public'] = self.public
|
result['public'] = self.public
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -95,29 +97,6 @@ class StuffedArea(AreaFeature):
|
||||||
default_related_name = 'stuffedareas'
|
default_related_name = 'stuffedareas'
|
||||||
|
|
||||||
|
|
||||||
class Escalator(AreaFeature):
|
|
||||||
"""
|
|
||||||
An escalator area
|
|
||||||
"""
|
|
||||||
DIRECTIONS = (
|
|
||||||
(True, _('up')),
|
|
||||||
(False, _('down')),
|
|
||||||
)
|
|
||||||
direction = models.BooleanField(verbose_name=_('direction'), choices=DIRECTIONS)
|
|
||||||
|
|
||||||
geomtype = 'polygon'
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
verbose_name = _('Escalator')
|
|
||||||
verbose_name_plural = _('Escalators')
|
|
||||||
default_related_name = 'escalators'
|
|
||||||
|
|
||||||
def get_geojson_properties(self):
|
|
||||||
result = super().get_geojson_properties()
|
|
||||||
result['direction'] = 'up' if self.direction else 'down'
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
class Stair(AreaFeature):
|
class Stair(AreaFeature):
|
||||||
"""
|
"""
|
||||||
A stair
|
A stair
|
||||||
|
@ -146,7 +125,7 @@ class Stair(AreaFeature):
|
||||||
('type', 'shadow'),
|
('type', 'shadow'),
|
||||||
('original_type', self.__class__.__name__.lower()),
|
('original_type', self.__class__.__name__.lower()),
|
||||||
('original_name', self.name),
|
('original_name', self.name),
|
||||||
('level', self.level.name),
|
('area', self.area.name),
|
||||||
))),
|
))),
|
||||||
('geometry', format_geojson(mapping(shadow), round=False)),
|
('geometry', format_geojson(mapping(shadow), round=False)),
|
||||||
))
|
))
|
||||||
|
@ -156,9 +135,6 @@ class Obstacle(AreaFeature):
|
||||||
"""
|
"""
|
||||||
An obstacle
|
An obstacle
|
||||||
"""
|
"""
|
||||||
crop_to_level = models.ForeignKey('mapdata.Level', on_delete=models.CASCADE, null=True, blank=True,
|
|
||||||
verbose_name=_('crop to other level'), related_name='crops_obstacles')
|
|
||||||
|
|
||||||
geomtype = 'polygon'
|
geomtype = 'polygon'
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -166,12 +142,6 @@ class Obstacle(AreaFeature):
|
||||||
verbose_name_plural = _('Obstacles')
|
verbose_name_plural = _('Obstacles')
|
||||||
default_related_name = 'obstacles'
|
default_related_name = 'obstacles'
|
||||||
|
|
||||||
def get_geojson_properties(self):
|
|
||||||
result = super().get_geojson_properties()
|
|
||||||
if self.crop_to_level is not None:
|
|
||||||
result['crop_to_level'] = self.crop_to_level.name
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
class LineObstacle(AreaFeature):
|
class LineObstacle(AreaFeature):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -15,7 +15,6 @@ class Level(Feature):
|
||||||
name = models.SlugField(_('level name'), unique=True, max_length=50,
|
name = models.SlugField(_('level name'), unique=True, max_length=50,
|
||||||
help_text=_('Usually just an integer (e.g. -1, 0, 1, 2)'))
|
help_text=_('Usually just an integer (e.g. -1, 0, 1, 2)'))
|
||||||
altitude = models.DecimalField(_('level altitude'), null=False, unique=True, max_digits=6, decimal_places=2)
|
altitude = models.DecimalField(_('level altitude'), null=False, unique=True, max_digits=6, decimal_places=2)
|
||||||
intermediate = models.BooleanField(_('intermediate level'))
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _('Level')
|
verbose_name = _('Level')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue