diff --git a/CHANGELOG b/CHANGELOG index 0c8f8a4c..cad1f318 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +- Force l'unicité des logins clipper - Nouveau site du COF en wagtail - Meilleurs affichage des longues listes de spectacles à cocher dans BdA-Revente - Bugfix : les pages de la revente ne sont plus accessibles qu'aux membres du diff --git a/gestioncof/migrations/0016_unique_clippers.py b/gestioncof/migrations/0016_unique_clippers.py new file mode 100644 index 00000000..dced5148 --- /dev/null +++ b/gestioncof/migrations/0016_unique_clippers.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.18 on 2019-01-14 21:36 +from __future__ import unicode_literals + +from django.db import migrations, models + + +def empty_clippers_to_null(apps, schema_editor): + CofProfile = apps.get_model("gestioncof", "CofProfile") + CofProfile.objects.filter(login_clipper="").update(login_clipper=None) + + +def null_clippers_to_empty(apps, schema_editor): + CofProfile = apps.get_model("gestioncof", "CofProfile") + CofProfile.objects.filter(login_clipper__isnull=True).update(login_clipper="") + + +class Migration(migrations.Migration): + + dependencies = [("gestioncof", "0015_psql_choices_niveaux")] + + operations = [ + # First, only set null to True (unique is still False) + migrations.AlterField( + model_name="cofprofile", + name="login_clipper", + field=models.CharField( + blank=True, max_length=32, null=True, verbose_name="Login clipper" + ), + ), + # Then, set all empty login_clippers to null + migrations.RunPython(empty_clippers_to_null), + # Finally set unique to True + migrations.AlterField( + model_name="cofprofile", + name="login_clipper", + field=models.CharField( + blank=True, + max_length=32, + null=True, + unique=True, + verbose_name="Login clipper", + ), + ), + ] diff --git a/gestioncof/models.py b/gestioncof/models.py index 98b947a1..e4975fc4 100644 --- a/gestioncof/models.py +++ b/gestioncof/models.py @@ -46,7 +46,9 @@ class CofProfile(models.Model): ) user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="profile") - login_clipper = models.CharField("Login clipper", max_length=32, blank=True) + login_clipper = models.CharField( + "Login clipper", max_length=32, blank=True, unique=True, null=True + ) is_cof = models.BooleanField("Membre du COF", default=False) phone = models.CharField("Téléphone", max_length=20, blank=True) occupation = models.CharField(