Amélioration des formulaires (détails)

This commit is contained in:
Jean-Marie Favreau 2024-10-16 11:45:04 +02:00
parent cd68d0039c
commit e3648f703b
2 changed files with 7 additions and 0 deletions

View File

@ -112,6 +112,8 @@ class EventForm(ModelForm):
if not is_authenticated:
del self.fields["status"]
self.fields['category'].queryset = self.fields['category'].queryset.order_by('name')
self.fields['category'].empty_label = None
self.fields['category'].initial = Category.get_default_category()
def clean_end_day(self):
start_day = self.cleaned_data.get("start_day")

View File

@ -609,6 +609,11 @@ class EventCreateView(SuccessMessageMixin, CreateView):
success_message = _("The event has been submitted and will be published as soon as it has been validated by the moderation team.")
form_class = EventForm
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs["is_authenticated"] = self.request.user.is_authenticated
return kwargs
def import_from_details(request):
form = EventForm(request.POST, is_authenticated=request.user.is_authenticated)