# -*- coding: utf-8 -*-
# Generated by Django 1.11.28 on 2020-04-28 16:01
from __future__ import unicode_literals

from django.db import migrations

updates = [
    {"from": "typesetting_article", "to": "typesetting_articles"},
]


def update_handshake_urls(apps, schema_editor):
    WorkflowElement = apps.get_model("core", "WorkflowElement")

    for update in updates:
        elements_to_update = WorkflowElement.objects.filter(
            handshake_url=update.get("from")
        )
        for element_to_update in elements_to_update:
            element_to_update.handshake_url = update.get("to")
            element_to_update.save()


def reverse_handshake_urls(apps, schema_editor):
    WorkflowElement = apps.get_model("core", "WorkflowElement")

    for update in updates:
        elements_to_update = WorkflowElement.objects.filter(
            handshake_url=update.get("to")
        )
        for element_to_update in elements_to_update:
            element_to_update.handshake_url = update.get("from")
            element_to_update.save()


class Migration(migrations.Migration):
    dependencies = [
        ("typesetting", "0009_typesettingcorrection"),
    ]

    operations = [
        migrations.RunPython(
            update_handshake_urls,
            reverse_code=reverse_handshake_urls,
        ),
    ]
