From 970a6b93f8d2acfa5b2bf0f0074043bde0700e89 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Wed, 23 Nov 2022 15:22:07 +0100 Subject: [PATCH 1/3] NullBooleanField is deprecated since Django 3.1 (#71619) It must be replaced by BooleanField(null=True). --- src/authentic2/a2_rbac/fields.py | 10 +++++----- .../a2_rbac/migrations/0025_auto_20210622_1132.py | 5 ++++- src/authentic2/a2_rbac/models.py | 8 ++++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/authentic2/a2_rbac/fields.py b/src/authentic2/a2_rbac/fields.py index e51f4678..9246357a 100644 --- a/src/authentic2/a2_rbac/fields.py +++ b/src/authentic2/a2_rbac/fields.py @@ -15,10 +15,10 @@ # along with this program. If not, see . from django import forms -from django.db.models import NullBooleanField +from django.db.models import BooleanField -class UniqueBooleanField(NullBooleanField): +class UniqueBooleanField(BooleanField): """BooleanField allowing only one True value in the table, and preventing problems with multiple False values by implicitely converting them to None.""" @@ -28,10 +28,10 @@ class UniqueBooleanField(NullBooleanField): kwargs['blank'] = True kwargs['null'] = True kwargs['default'] = False - super(NullBooleanField, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def deconstruct(self): - name, path, args, kwargs = super(NullBooleanField, self).deconstruct() + name, path, args, kwargs = super().deconstruct() del kwargs['null'] del kwargs['blank'] del kwargs['unique'] @@ -59,4 +59,4 @@ class UniqueBooleanField(NullBooleanField): else: defaults = {'form_class': forms.BooleanField} defaults.update(kwargs) - return super(NullBooleanField, self).formfield(**defaults) + return super().formfield(**defaults) diff --git a/src/authentic2/a2_rbac/migrations/0025_auto_20210622_1132.py b/src/authentic2/a2_rbac/migrations/0025_auto_20210622_1132.py index f3b4d8d0..90ab3df7 100644 --- a/src/authentic2/a2_rbac/migrations/0025_auto_20210622_1132.py +++ b/src/authentic2/a2_rbac/migrations/0025_auto_20210622_1132.py @@ -13,9 +13,12 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='organizationalunit', name='user_can_reset_password', - field=models.NullBooleanField( + field=models.BooleanField( choices=[(None, 'System default'), (True, 'Yes'), (False, 'No')], verbose_name='Users can reset password', + default=None, + blank=True, + null=True, ), ), ] diff --git a/src/authentic2/a2_rbac/models.py b/src/authentic2/a2_rbac/models.py index 394394fd..1462d87a 100644 --- a/src/authentic2/a2_rbac/models.py +++ b/src/authentic2/a2_rbac/models.py @@ -125,8 +125,12 @@ class OrganizationalUnit(AbstractBase): admin_perms = GenericRelation('Permission', content_type_field='target_ct', object_id_field='target_id') - user_can_reset_password = models.NullBooleanField( - verbose_name=_('Users can reset password'), choices=USER_CAN_RESET_PASSWD_CHOICES + user_can_reset_password = models.BooleanField( + verbose_name=_('Users can reset password'), + choices=USER_CAN_RESET_PASSWD_CHOICES, + null=True, + default=None, + blank=True, ) user_add_password_policy = models.IntegerField( -- 2.37.2