From 2a2666abe2043d8d406f7416475f56bfec93cee1 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Thu, 16 Nov 2023 22:35:19 +0100 Subject: [PATCH] [Fix] statut visible suivant authentification dans le formulaire https://forge.chapril.org/jmtrivial/agenda_culturel/issues/23 --- src/agenda_culturel/views.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index d9a6166..fb1f134 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -339,6 +339,12 @@ class EventForm(forms.ModelForm): 'end_time': forms.TextInput(attrs={'type': 'time'}), } + def __init__(self, instance, *args, **kwargs): + is_authenticated = kwargs.pop('is_authenticated', False) + super().__init__(instance=instance, *args, **kwargs) + if not is_authenticated: + del self.fields['status'] + class EventCreateView(CreateView): model = Event @@ -346,6 +352,12 @@ class EventCreateView(CreateView): form_class = EventForm template_name_suffix = "_create_form" + def get_form_kwargs(self): + kwargs = super().get_form_kwargs() + kwargs['is_authenticated'] = self.request.user.is_authenticated + return kwargs + + class EventUpdateView(SuccessMessageMixin, LoginRequiredMixin, UpdateView):