Fix add organizer view

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello 2023-04-04 10:25:33 +02:00
parent fc6e2593b4
commit 2a545dae10
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 4 additions and 8 deletions

View File

@ -92,21 +92,17 @@ class AddOrganizerView(VolunteerMixin, CreateView):
context["volunteer_registration_form"] = VolunteerRegistrationForm(self.request.POST or None)
del context["volunteer_registration_form"].fields["email_confirmed"]
if not self.request.user.registration.is_admin:
del context["volunteer_registration_form"].fields["admin"]
return context
def get_form(self, form_class=None):
form = super().get_form(form_class)
if not self.request.user.registration.is_admin:
del form.fields["admin"]
return form
@transaction.atomic
def form_valid(self, form):
registration_form = VolunteerRegistrationForm(self.request.POST)
del registration_form.fields["email_confirmed"]
if not self.request.user.registration.is_admin:
del registration_form.fields["admin"]
if not registration_form.is_valid():
return self.form_invalid(form)