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

from django.db import migrations

OLD_VALUE = "Dear {{ article.correspondence_author.full_name }},<br><br>We are requesting that you make some changes to your paper. Details of the changes required are below:<br><br>{{ revision.editor_note }}<br><br>You can access you revision here: <a href=\"{% journal_url 'do_revisions' article.pk revision.pk  %}\">{% journal_url 'do_revisions' article.pk revision.pk  %}</a><br><br>Your revisions are due on {{ revision.date_due }}.<br><br>Regards, <br>{{ request.user.signature|safe }}"
NEW_VALUE = "Dear {{ article.correspondence_author.full_name }},<br><br>We are requesting that you make some changes to your paper. Details of the changes required are below:<br><br>{{ revision.editor_note }}<br><br>You can access your revision here: <a href=\"{% journal_url 'do_revisions' article.pk revision.pk  %}\">{% journal_url 'do_revisions' article.pk revision.pk  %}</a><br><br>Your revisions are due on {{ revision.date_due }}.<br><br>Regards, <br>{{ request.user.signature|safe }}"


def replace_template(apps, schema_editor):
    SettingValueTranslation = apps.get_model("core", "SettingValueTranslation")
    settings = SettingValueTranslation.objects.filter(value=OLD_VALUE)

    for setting in settings:
        setting.value = NEW_VALUE
        setting.save()


def reverse_code(apps, schema_editor):
    SettingValueTranslation = apps.get_model("core", "SettingValueTranslation")
    settings = SettingValueTranslation.objects.filter(value=NEW_VALUE)
    for setting in settings:
        setting.value = OLD_VALUE
        setting.save()


class Migration(migrations.Migration):
    dependencies = [
        ("core", "0034_fix_wrong_signature_review_ack"),
    ]

    operations = [
        migrations.RunPython(replace_template, reverse_code=reverse_code),
    ]
