# Generated by Django 3.1.6 on 2021-03-16 13:00

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


class Migration(migrations.Migration):
    dependencies = [
        ("people", "0004_display_name_and_image"),
        ("data_france", "0019_auto_20210209_0834"),
        ("elus", "0018_auto_20210204_1519"),
    ]

    operations = [
        migrations.CreateModel(
            name="RechercheParrainageMaire",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "created",
                    models.DateTimeField(
                        default=django.utils.timezone.now,
                        editable=False,
                        verbose_name="date de création",
                    ),
                ),
                (
                    "modified",
                    models.DateTimeField(
                        auto_now=True, verbose_name="dernière modification"
                    ),
                ),
                (
                    "statut",
                    models.IntegerField(
                        choices=[
                            (1, "En cours"),
                            (2, "Promesse obtenue"),
                            (3, "Promesse bien reçue et validée"),
                            (4, "Promesse refusée"),
                            (5, "Recherche annulée"),
                        ],
                        default=1,
                    ),
                ),
                (
                    "commentaires",
                    models.TextField(
                        blank=True,
                        help_text="Indiquez-ici tout détail supplémentaire pertinent.",
                        verbose_name="Commentaires",
                    ),
                ),
                (
                    "formulaire",
                    models.FileField(
                        null=True,
                        upload_to=dynamic_filenames.FilePattern(
                            filename_pattern="/elus/parrainages/{uuid:.30base32}{ext}"
                        ),
                        verbose_name="Formulaire de promesse signé",
                    ),
                ),
                (
                    "elu",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="data_france.elumunicipal",
                    ),
                ),
                (
                    "person",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE, to="people.person"
                    ),
                ),
            ],
            options={
                "verbose_name": "Recherche de parrainage de maire",
                "verbose_name_plural": "Recherches de parrainages de maires",
                "permissions": [
                    ("acces_parrainages", "Donne l'accès à l'interface de parrainage")
                ],
            },
        ),
        migrations.AddConstraint(
            model_name="rechercheparrainagemaire",
            constraint=models.UniqueConstraint(
                condition=models.Q(_negated=True, statut=5),
                fields=("elu",),
                name="recherche_parrainage_un_seul_actif",
            ),
        ),
    ]
