Projet

Général

Profil

0001-NullBooleanField-is-deprecated-since-Django-3.1-7161.patch

Benjamin Dauvergne, 24 novembre 2022 14:47

Télécharger (3,57 ko)

Voir les différences:

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(-)
src/authentic2/a2_rbac/fields.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
from django import forms
18
from django.db.models import NullBooleanField
18
from django.db.models import BooleanField
19 19

  
20 20

  
21
class UniqueBooleanField(NullBooleanField):
21
class UniqueBooleanField(BooleanField):
22 22
    """BooleanField allowing only one True value in the table, and preventing
23 23
    problems with multiple False values by implicitely converting them to
24 24
    None."""
......
28 28
        kwargs['blank'] = True
29 29
        kwargs['null'] = True
30 30
        kwargs['default'] = False
31
        super(NullBooleanField, self).__init__(*args, **kwargs)
31
        super().__init__(*args, **kwargs)
32 32

  
33 33
    def deconstruct(self):
34
        name, path, args, kwargs = super(NullBooleanField, self).deconstruct()
34
        name, path, args, kwargs = super().deconstruct()
35 35
        del kwargs['null']
36 36
        del kwargs['blank']
37 37
        del kwargs['unique']
......
59 59
        else:
60 60
            defaults = {'form_class': forms.BooleanField}
61 61
        defaults.update(kwargs)
62
        return super(NullBooleanField, self).formfield(**defaults)
62
        return super().formfield(**defaults)
src/authentic2/a2_rbac/migrations/0025_auto_20210622_1132.py
13 13
        migrations.AlterField(
14 14
            model_name='organizationalunit',
15 15
            name='user_can_reset_password',
16
            field=models.NullBooleanField(
16
            field=models.BooleanField(
17 17
                choices=[(None, 'System default'), (True, 'Yes'), (False, 'No')],
18 18
                verbose_name='Users can reset password',
19
                default=None,
20
                blank=True,
21
                null=True,
19 22
            ),
20 23
        ),
21 24
    ]
src/authentic2/a2_rbac/models.py
125 125

  
126 126
    admin_perms = GenericRelation('Permission', content_type_field='target_ct', object_id_field='target_id')
127 127

  
128
    user_can_reset_password = models.NullBooleanField(
129
        verbose_name=_('Users can reset password'), choices=USER_CAN_RESET_PASSWD_CHOICES
128
    user_can_reset_password = models.BooleanField(
129
        verbose_name=_('Users can reset password'),
130
        choices=USER_CAN_RESET_PASSWD_CHOICES,
131
        null=True,
132
        default=None,
133
        blank=True,
130 134
    )
131 135

  
132 136
    user_add_password_policy = models.IntegerField(
133
-