convert data of room- and level-Arealocations to Sections and Spaces

This commit is contained in:
Laura Klünder 2017-05-10 19:31:38 +02:00
parent 8290083fd4
commit b77086f8ed

View file

@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-05-10 17:10
from __future__ import unicode_literals
from django.db import migrations
def assign_locations_level_room(apps, schema_editor):
AreaLocation = apps.get_model('mapdata', 'AreaLocation')
Space = apps.get_model('mapdata', 'Space')
Section = apps.get_model('mapdata', 'Section')
Space.objects.all().update(can_search=False, can_describe=False)
Section.objects.all().update(can_search=False, can_describe=False)
for obj in AreaLocation.objects.filter(location_type__in=('level', 'room')):
to_obj = None
if obj.location_type == 'level':
to_obj = obj.section
elif obj.location_type == 'room':
spaces = [s for s in Space.objects.filter(section=obj.section, level='')
if s.geometry.intersection(obj.geometry).area / s.geometry.area > 0.90]
if len(spaces) == 0:
obj.location_type = 'roomsegment'
obj.save()
continue
elif len(spaces) > 1:
obj.location_type = 'roomsegment'
obj.save()
continue
to_obj = spaces[0]
# we need to to this setting the value directly does not work in a migration for some reason
inner = to_obj.locationslug_ptr
inner.slug = obj.slug
inner.save()
to_obj.titles = obj.titles
to_obj.can_search = obj.can_search
to_obj.can_describe = obj.can_describe
to_obj.color = obj.color
to_obj.save()
to_obj.groups.add(*obj.groups.all())
to_obj.save()
obj.delete()
class Migration(migrations.Migration):
dependencies = [
('mapdata', '0084_auto_20170510_1701'),
]
operations = [
migrations.RunPython(assign_locations_level_room),
]