From d85eeb58013ce7d2982bff0e8ff6e93331db0f30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Mon, 14 Jan 2019 22:46:16 +0100 Subject: [PATCH 1/2] Enforce clipper uniqueness --- gestioncof/migrations/0016_unique_clippers.py | 45 +++++++++++++++++++ gestioncof/models.py | 4 +- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 gestioncof/migrations/0016_unique_clippers.py 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( From 68cead600f28f96c1b6e742d59f9473797c28ac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Mon, 14 Jan 2019 23:12:14 +0100 Subject: [PATCH 2/2] CHANGELOG: clipper uniqueness --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) 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