Projet

Général

Profil

Bug #53444

agendas : création/duplication du premier guichet à chaque modif de rôle

Ajouté par Thomas Noël il y a environ 3 ans. Mis à jour il y a environ 3 ans.

Statut:
Fermé
Priorité:
Haut
Assigné à:
Catégorie:
-
Version cible:
-
Début:
26 avril 2021
Echéance:
% réalisé:

0%

Temps estimé:
Patch proposed:
Oui
Planning:
Non

Description

Signalé sur #53436 : création/duplication du premier guichet à chaque modif de rôle

Pour reproduire :
  • créer un agenda rendez-vous, il a un guichet, normal
  • modifier un rôle dans les permission
  • un nouveau guichet apparait, avec le même nom (mais un slug suffixé par "-1")

Fichiers

Révisions associées

Révision 000ea8dc (diff)
Ajouté par Thomas Noël il y a environ 3 ans

manager: create a new desk only on new meetings agendas (#53444)

Révision 274bcb11 (diff)
Ajouté par Thomas Noël il y a environ 3 ans

manager: create a new desk only on new meetings agendas (#53444)

Historique

#3

Mis à jour par Thomas Noël il y a environ 3 ans

C'est dans le save qu'on ajoute toujours un guichet sur les agendas meetings... heu...?

 56 class AgendaAddForm(forms.ModelForm):
(...)
 68     def save(self, *args, **kwargs):
 69         super().save()
 70         if self.instance.kind == 'meetings':
 71             default_desk = self.instance.desk_set.create(label=_('Desk 1'))
 72             default_desk.import_timeperiod_exceptions_from_settings(enable=True)
 73             self.instance.desk_simple_management = True
 74             self.instance.save()
 75         return self.instance
#4

Mis à jour par Thomas Noël il y a environ 3 ans

Vient de #48924 (janvier, ouch !)

#5

Mis à jour par Thomas Noël il y a environ 3 ans

  • Assigné à mis à Thomas Noël

Ma piste en mode un peu cowboy :

diff --git a/chrono/manager/forms.py b/chrono/manager/forms.py
index 92928fd..6e1367a 100644
--- a/chrono/manager/forms.py
+++ b/chrono/manager/forms.py
@@ -67,7 +67,7 @@ class AgendaAddForm(forms.ModelForm):

     def save(self, *args, **kwargs):
         super().save()
-        if self.instance.kind == 'meetings':
+        if self.instance.kind == 'meetings' and self.instance.desk_set.count() == 0:
             default_desk = self.instance.desk_set.create(label=_('Desk 1'))
             default_desk.import_timeperiod_exceptions_from_settings(enable=True)
             self.instance.desk_simple_management = True

(je vois pour écrire un test)

#6

Mis à jour par Thomas Noël il y a environ 3 ans

NB : je n'ai pas regardé si ce pattern de création de desk existe ailleurs.

#7

Mis à jour par Lauréline Guérin il y a environ 3 ans

Il s'agit du form AgendaAddForm, utilisé uniquement en création (vue AgendaAddView), pourquoi le fait de modifier un rôle fait intervenir ce form ?

#8

Mis à jour par Lauréline Guérin il y a environ 3 ans

class AgendaRolesForm(AgendaAddForm):
    class Meta:
        model = Agenda
        fields = [
            'edit_role',
            'view_role',
        ]

rhooo ... changer pour AgendaEditForm ?

#9

Mis à jour par Lauréline Guérin il y a environ 3 ans

ou pas, les fields, toussa.
ok pour vérifier l'existence d'un desk (avec un .exists), mais ça serait encore mieux de vérifier si la pk existe avant le super:

        create = self.instance.pk is None
        super().save()
        if create and self.instance.kind == 'meetings':

#10

Mis à jour par Thomas Noël il y a environ 3 ans

Lauréline Guerin a écrit :

ou pas, les fields, toussa.
ok pour vérifier l'existence d'un desk (avec un .exists), mais ça serait encore mieux de vérifier si la pk existe avant le super:

Yep, voici donc.

#11

Mis à jour par Lauréline Guérin il y a environ 3 ans

  • Statut changé de Solution proposée à Solution validée

ok, mais jenkins a l'air de faire n'importe quoi sur cette branche :/

#12

Mis à jour par Lauréline Guérin il y a environ 3 ans

c'est bon c'est vert

#13

Mis à jour par Thomas Noël il y a environ 3 ans

  • Statut changé de Solution validée à Résolu (à déployer)
commit 000ea8dc07ac5c9471f8650af6af59def214aa72
Author: Thomas NOËL <tnoel@entrouvert.com>
Date:   Mon Apr 26 22:15:04 2021 +0200

    manager: create a new desk only on new meetings agendas (#53444)

Et je prépare un hotfix/v1.77

#14

Mis à jour par Frédéric Péters il y a environ 3 ans

  • Statut changé de Résolu (à déployer) à Solution déployée

Formats disponibles : Atom PDF