[Fix] statut visible suivant authentification dans le formulaire #23
This commit is contained in:
parent
07f89d209b
commit
2a2666abe2
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user