Project

General

Profile

Bug #57138

en cas de doublon, la création des slugs ajoute 1, puis 12, puis 123

Added by Thomas Noël 26 days ago. Updated 2 days ago.

Status:
Résolu (à déployer)
Priority:
Normal
Assignee:
Category:
-
Target version:
-
Start date:
21 Sep 2021
Due date:
% Done:

0%

Estimated time:
Patch proposed:
Yes
Planning:
No

Description

vu sur une instance multi-collectivité Publik, des slugs "administreur", "administreur1", "administreur12", "administreur123" : il y a certainement un algo de création de slug unique un peu défaillant


Files

Associated revisions

Revision 0a3b4686 (diff)
Added by Thomas Noël 2 days ago

manager: make slug conflict resolution simpler (#57138)

History

#2

Updated by Thomas Noël 26 days ago

C'est dans src/authentic2/manager/forms.py

class SlugMixin(forms.ModelForm):
    def save(self, commit=True):
        instance = self.instance
        if not instance.slug:
            instance.slug = slugify(str(instance.name)).lstrip('_')
            qs = instance.__class__.objects.all()
            if instance.pk:
                qs = qs.exclude(pk=instance.pk)
            i = 1
            while qs.filter(slug=instance.slug).exists():
                instance.slug += str(i)                       <-- ici
                i += 1
        if len(instance.slug) > 256:
            instance.slug = instance.slug[:252] + hashlib.md5(instance.slug).hexdigest()[:4]
        return super().save(commit=commit)
#3

Updated by Thomas Noël 24 days ago

#4

Updated by Serghei Mihai 24 days ago

  • Status changed from Solution proposée to Solution validée
#5

Updated by Thomas Noël 2 days ago

  • Status changed from Solution validée to Résolu (à déployer)
commit 0a3b4686227756f070bc82cfbb538b6b1a202ba5
Author: Thomas NOEL <tnoel@entrouvert.com>
Date:   Tue Sep 21 15:30:47 2021 +0200

    manager: make slug conflict resolution simpler (#57138)

Also available in: Atom PDF