<commit_before># Generated by Django 2.2.2 on 2019-07-03 08:25

import django.utils.timezone
from django.db import migrations, models

import agir.lib.models


def initialize_created(apps, schema):
    Notification = apps.get_model("notifications", "Notification")
    Announcement = apps.get_model("notifications", "Announcement")

    Notification.objects.filter(announcement__isnull=False).annotate(
        start_date=models.Subquery(
            Announcement.objects.filter(pk=models.OuterRef("announcement_id")).values(
                "start_date"
            )
        )
    ).update(created=models.F("start_date"))


class Migration(migrations.Migration):

    dependencies = [
        ("mailing", "0002_auto_20190308_1859"),
        ("notifications", "0001_initial"),
    ]

    operations = [
        migrations.RenameModel(old_name="Notification", new_name="Announcement"),
        migrations.RenameModel(old_name="NotificationStatus", new_name="Notification"),
        migrations.AlterModelOptions(
            name="notification", options={"ordering": ("-created",)}
        ),
        migrations.AlterField(
            model_name="notification",
            name="status",
            field=models.CharField(
                choices=[("U", "Non vue"), ("S", "Vue"), ("C", "Cliquée")],
                max_length=1,
                verbose_name="Status",
                default="U",
            ),
        ),
        migrations.AlterField(
            model_name="notification",
            name="person",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="notifications",
                related_query_name="notification",
                to="people.Person",
            ),
        ),
        migrations.RenameField(
            model_name="notification", old_name="notification", new_name="announcement"
        ),
        migrations.AlterField(
            model_name="notification",
            name="announcement",
            field=models.ForeignKey(
                null=True,
                on_delete=models.deletion.CASCADE,
                related_name="notifications",
                related_query_name="notification",
                to="notifications.Announcement",
            ),
        ),
        migrations.AddField(
            model_name="notification",
            name="created",
            field=models.DateTimeField(
                default=django.utils.timezone.now,
                editable=False,
                verbose_name="created",
            ),
        ),
        migrations.AddField(
            model_name="notification",
            name="modified",
            field=models.DateTimeField(auto_now=True, verbose_name="modified"),
        ),
        migrations.AddField(
            model_name="notification",
            name="content",
            field=agir.lib.models.DescriptionField(
                blank=True, verbose_name="Contenu de la notification"
            ),
        ),
        migrations.AddField(
            model_name="notification",
            name="icon",
            field=models.CharField(
                blank=True,
                default="exclamation",
                help_text='Indiquez le nom d\'une icône dans <a href="https://fontawesome.com/v4.7.0/icons/">cette liste</a>',
                max_length=200,
                verbose_name="icône",
            ),
        ),
        migrations.AddField(
            model_name="notification",
            name="link",
            field=models.URLField(blank=True, verbose_name="Lien"),
        ),
        migrations.AddConstraint(
            model_name="notification",
            constraint=models.CheckConstraint(
                check=models.Q(
                    models.Q(
                        ("content__isnull", False),
                        ("announcement__isnull", False),
                        _connector="OR",
                    ),
                    models.Q(
                        ("icon__isnull", False),
                        ("announcement__isnull", False),
                        _connector="OR",
                    ),
                ),
                name="has_content",
            ),
        ),
        migrations.AlterModelOptions(
            name="announcement",
            options={"ordering": ("start_date", "end_date"), "verbose_name": "Annonce"},
        ),
        migrations.AlterField(
            model_name="announcement",
            name="icon",
            field=models.CharField(
                default="exclamation",
                help_text='Indiquez le nom d\'une icône dans <a href="https://fontawesome.com/v4.7.0/icons/">cette liste</a>',
                max_length=200,
                verbose_name="icône",
            ),
        ),
        migrations.RunPython(
            code=initialize_created, reverse_code=migrations.RunPython.noop
        ),
    ]<commit_msg>fix(notifications): rend la migration réversible<commit_after># Generated by Django 2.2.2 on 2019-07-03 08:25

import django.utils.timezone
from django.db import migrations, models

import agir.lib.models


def initialize_created(apps, schema):
    Notification = apps.get_model("notifications", "Notification")
    Announcement = apps.get_model("notifications", "Announcement")

    Notification.objects.filter(announcement__isnull=False).annotate(
        start_date=models.Subquery(
            Announcement.objects.filter(pk=models.OuterRef("announcement_id")).values(
                "start_date"
            )
        )
    ).update(created=models.F("start_date"))


def delete_personal_notifications(apps, schema):
    Notification = apps.get_model("notifications", "Notification")
    Notification.objects.filter(announcement_id=None).delete()


class Migration(migrations.Migration):

    dependencies = [
        ("mailing", "0002_auto_20190308_1859"),
        ("notifications", "0001_initial"),
    ]

    operations = [
        migrations.RenameModel(old_name="Notification", new_name="Announcement"),
        migrations.RenameModel(old_name="NotificationStatus", new_name="Notification"),
        migrations.AlterModelOptions(
            name="notification", options={"ordering": ("-created",)}
        ),
        migrations.AlterField(
            model_name="notification",
            name="status",
            field=models.CharField(
                choices=[("U", "Non vue"), ("S", "Vue"), ("C", "Cliquée")],
                max_length=1,
                verbose_name="Status",
                default="U",
            ),
        ),
        migrations.AlterField(
            model_name="notification",
            name="person",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="notifications",
                related_query_name="notification",
                to="people.Person",
            ),
        ),
        migrations.RenameField(
            model_name="notification", old_name="notification", new_name="announcement"
        ),
        migrations.AlterField(
            model_name="notification",
            name="announcement",
            field=models.ForeignKey(
                null=True,
                on_delete=models.deletion.CASCADE,
                related_name="notifications",
                related_query_name="notification",
                to="notifications.Announcement",
            ),
        ),
        migrations.AddField(
            model_name="notification",
            name="created",
            field=models.DateTimeField(
                default=django.utils.timezone.now,
                editable=False,
                verbose_name="created",
            ),
        ),
        migrations.AddField(
            model_name="notification",
            name="modified",
            field=models.DateTimeField(auto_now=True, verbose_name="modified"),
        ),
        migrations.AddField(
            model_name="notification",
            name="content",
            field=agir.lib.models.DescriptionField(
                blank=True, verbose_name="Contenu de la notification"
            ),
        ),
        migrations.AddField(
            model_name="notification",
            name="icon",
            field=models.CharField(
                blank=True,
                default="exclamation",
                help_text='Indiquez le nom d\'une icône dans <a href="https://fontawesome.com/v4.7.0/icons/">cette liste</a>',
                max_length=200,
                verbose_name="icône",
            ),
        ),
        migrations.AddField(
            model_name="notification",
            name="link",
            field=models.URLField(blank=True, verbose_name="Lien"),
        ),
        migrations.AddConstraint(
            model_name="notification",
            constraint=models.CheckConstraint(
                check=models.Q(
                    models.Q(
                        ("content__isnull", False),
                        ("announcement__isnull", False),
                        _connector="OR",
                    ),
                    models.Q(
                        ("icon__isnull", False),
                        ("announcement__isnull", False),
                        _connector="OR",
                    ),
                ),
                name="has_content",
            ),
        ),
        migrations.AlterModelOptions(
            name="announcement",
            options={"ordering": ("start_date", "end_date"), "verbose_name": "Annonce"},
        ),
        migrations.AlterField(
            model_name="announcement",
            name="icon",
            field=models.CharField(
                default="exclamation",
                help_text='Indiquez le nom d\'une icône dans <a href="https://fontawesome.com/v4.7.0/icons/">cette liste</a>',
                max_length=200,
                verbose_name="icône",
            ),
        ),
        migrations.RunPython(
            code=initialize_created, reverse_code=delete_personal_notifications
        ),
    ]
{'fraction_non_alphanumeric': 0.11678543151227237, 'fraction_numerical': 0.009501187648456057, 'mean_word_length': 1.736257784998646, 'pattern_counts': {'":': 6, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5211383', 'n_tokens_mistral': 2733, 'n_tokens_neox': 2610, 'n_words': 347}