# Generated by Django 2.0.4 on 2018-04-23 12:36
from django.contrib.gis.geos import Point

from django.db import migrations


def forwards_func(apps, schema_editor):
    change_region_center(apps, schema_editor, True)


def reverse_func(apps, schema_editor):
    change_region_center(apps, schema_editor, False)


class Migration(migrations.Migration):

    dependencies = [
        ('regions', '0008_federalsubjectwithpolygon'),
    ]

    operations = [
        migrations.RunPython(forwards_func, reverse_func),
    ]


def change_region_center(apps, schema_editor, forward=True):
    FederalSubjectWithPolygon = apps.get_model("regions", "FederalSubjectWithPolygon")
    # region_id: center point
    # see data/0002/federal_subject.jsonl
    data_list = {
        # Архангельская область
        8: Point(40.86914062499997, 64.2445947679819)
    }

    for region_id, center in data_list.items():
        fswp = FederalSubjectWithPolygon.objects.get(id=region_id)
        fswp.center = center if forward else None
        fswp.save(update_fields=['center'])
