From 408aa51e5b7a491a4f5e4560b8754165b35afae6 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Mon, 4 Oct 2021 10:02:16 +0200 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9e=20des=20utilisateurs=20inactifs=20pou?= =?UTF-8?q?r=20les=20=C3=A9lections=20avec=20liste,=20pour=20ne=20pas=20le?= =?UTF-8?q?s=20inclure=20dans=20la=20r=C3=A9initialisation=20de=20mdp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- elections/migrations/0033_inactive_users.py | 21 +++++++++++++++++++++ elections/utils.py | 1 + 2 files changed, 22 insertions(+) create mode 100644 elections/migrations/0033_inactive_users.py diff --git a/elections/migrations/0033_inactive_users.py b/elections/migrations/0033_inactive_users.py new file mode 100644 index 0000000..0c98cae --- /dev/null +++ b/elections/migrations/0033_inactive_users.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.6 on 2021-10-04 07:49 + +from django.db import migrations + + +def set_users_inactive(apps, schema_editor): + db_alias = schema_editor.connection.alias + User = apps.get_model("elections", "User") + + User.objects.using(db_alias).filter(election__isnull=False).update(is_active=False) + + +class Migration(migrations.Migration): + + dependencies = [ + ("elections", "0032_auto_20210820_0023"), + ] + + operations = [ + migrations.RunPython(set_users_inactive, migrations.RunPython.noop), + ] diff --git a/elections/utils.py b/elections/utils.py index 32499f7..27dfc97 100644 --- a/elections/utils.py +++ b/elections/utils.py @@ -334,6 +334,7 @@ def create_users(election, csv_file): username=f"{election.id}__{username}", email=email, full_name=full_name, + is_active=False, ) for (username, full_name, email) in reader ]