Skip to content
Snippets Groups Projects

Use all_cleaned_data instead of seperate cleaned_data per step

Merged Tom Teichler requested to merge fix-registration into master
Files
2
@@ -464,12 +464,11 @@ class RegisterEventWizardView(SessionWizardView):
initial = self.initial_dict.get(step, {})
cleaned_data = self.get_all_cleaned_data()
if step == "register":
if "domain" in cleaned_data:
domain = cleaned_data["domain"]
email = f"{cleaned_data['local_part']}@{domain.domain}"
cleaned_data_email = self.get_cleaned_data_for_step("email")
if cleaned_data_email:
domain = cleaned_data_email["domain"]
email = f"{cleaned_data_email['local_part']}@{domain.domain}"
initial.update(
{
"email": email,
@@ -509,13 +508,14 @@ class RegisterEventWizardView(SessionWizardView):
)
else:
if "first_name" in cleaned_data:
cleaned_data_register = self.get_cleaned_data_for_step("register")
if cleaned_data_register:
initial.update(
{
"first_name": cleaned_data["first_name"],
"last_name": cleaned_data["last_name"],
"email": cleaned_data["email"],
"date_of_birth": cleaned_data["date_of_birth"],
"first_name": cleaned_data_register["first_name"],
"last_name": cleaned_data_register["last_name"],
"email": cleaned_data_register["email"],
"date_of_birth": cleaned_data_register["date_of_birth"],
}
)
@@ -524,11 +524,17 @@ class RegisterEventWizardView(SessionWizardView):
def done(self, form_list, **kwargs):
event = Event.objects.get(slug=self.kwargs["slug"])
cleaned_data = self.get_all_cleaned_data()
cleaned_data_email = self.get_cleaned_data_for_step("email")
cleaned_data_contact_details = self.get_cleaned_data_for_step("contact_details")
cleaned_data_guardians = self.get_cleaned_data_for_step("guardians")
cleaned_data_register = self.get_cleaned_data_for_step("register")
cleaned_data_additional = self.get_cleaned_data_for_step("additional")
cleaned_data_financial = self.get_cleaned_data_for_step("financial")
cleaned_data_consent = self.get_cleaned_data_for_step("consent")
if "voucher_code" in cleaned_data:
if cleaned_data_financial["voucher_code"]:
vouchers = Voucher.objects.filter(
person=person, event=event, used=False, code=cleaned_data["voucher_code"]
person=person, event=event, used=False, code=cleaned_data_financial["voucher_code"]
)
if vouchers:
voucher = vouchers.first()
@@ -536,19 +542,19 @@ class RegisterEventWizardView(SessionWizardView):
messages.error(self.request, _("You entered an invalid voucher code!"))
# Create email address
if "local_part" in cleaned_data:
if cleaned_data_email:
_email = MailAddress.objects.create(
local_part=cleaned_data["local_part"],
domain=cleaned_data["domain"],
local_part=cleaned_data_email["local_part"],
domain=cleaned_data_email["domain"],
)
# Create user
if "username" in cleaned_data:
if cleaned_data_register:
user = User.objects.create(
username=cleaned_data["username"],
email=cleaned_data["email"],
username=cleaned_data_register["username"],
email=cleaned_data_register["email"],
)
user.set_password(cleaned_data["password1"])
user.set_password(cleaned_data_register["password1"])
user.save()
else:
user = self.request.user
@@ -556,73 +562,73 @@ class RegisterEventWizardView(SessionWizardView):
person, created = Person.objects.get_or_create(
user=user,
defaults={
"email": cleaned_data["email"],
"first_name": cleaned_data["first_name"],
"last_name": cleaned_data["last_name"],
"email": cleaned_data_contact_details["email"],
"first_name": cleaned_data_contact_details["first_name"],
"last_name": cleaned_data_contact_details["last_name"],
},
)
if (
"mobile_number" in cleaned_data
or "sex" in cleaned_data
or "date_of_birth" in cleaned_data
"mobile_number" in cleaned_data_contact_details
or "sex" in cleaned_data_contact_details
or "date_of_birth" in cleaned_data_contact_details
):
person.mobile_number = cleaned_data["mobile_number"]
person.sex = cleaned_data["sex"]
person.date_of_birth = cleaned_data["date_of_birth"]
person.mobile_number = cleaned_data_contact_details["mobile_number"]
person.sex = cleaned_data_contact_details["sex"]
person.date_of_birth = cleaned_data_contact_details["date_of_birth"]
person.save()
# Store postal address in database
if (
"postal_code" in cleaned_data
or "place" in cleaned_data
or "street" in cleaned_data
"postal_code" in cleaned_data_contact_details
or "place" in cleaned_data_contact_details
or "street" in cleaned_data_contact_details
):
person.street = cleaned_data["street"]
person.postal_code = cleaned_data["postal_code"]
person.place = cleaned_data["place"]
person.housenumber = cleaned_data["housenumber"]
person.street = cleaned_data_contact_details["street"]
person.postal_code = cleaned_data_contact_details["postal_code"]
person.place = cleaned_data_contact_details["place"]
person.housenumber = cleaned_data_contact_details["housenumber"]
person.save()
if (
"guardian_first_name" in cleaned_data
or "guardian_last_name" in cleaned_data
or "guardian_mobile_number" in cleaned_data
or "guardian_email" in cleaned_data
"guardian_first_name" in cleaned_data_guardians
or "guardian_last_name" in cleaned_data_guardians
or "guardian_mobile_number" in cleaned_data_guardians
or "guardian_email" in cleaned_data_guardians
):
guardian, created = Person.objects.get_or_create(
defaults={
"mobile_number": cleaned_data["guardian_mobile_number"],
"mobile_number": cleaned_data_guardians["guardian_mobile_number"],
},
first_name=cleaned_data["guardian_first_name"],
last_name=cleaned_data["guardian_last_name"],
email=cleaned_data["guardian_email"],
first_name=cleaned_data_guardians["guardian_first_name"],
last_name=cleaned_data_guardians["guardian_last_name"],
email=cleaned_data_guardians["guardian_email"],
)
person.guardians.add(guardian)
person.save()
if cleaned_data:
if cleaned_data_email:
_email.person = person
_email.save()
registration = EventRegistration.objects.create(
event=event,
person=person,
medical_information=cleaned_data["medical_information"],
donation=cleaned_data["donation"],
school=cleaned_data["school"],
school_class=cleaned_data["school_class"],
school_place=cleaned_data["school_place"],
medical_information=cleaned_data_additional["medical_information"],
donation=cleaned_data_financial["donation"],
school=cleaned_data_contact_details["school"],
school_class=cleaned_data_contact_details["school_class"],
school_place=cleaned_data_contact_details["school_place"],
)
for field in event.linked_group.additional_fields.all():
registration.extended_data[
slugify(field.title).replace("-", "_")
] = cleaned_data[field.title]
] = cleaned_data_additional[field.title]
for field in cleaned_data:
for field in cleaned_data_consent:
if not field.startswith("consent_"):
continue
pk = int(field.split("_")[1])
@@ -631,9 +637,9 @@ class RegisterEventWizardView(SessionWizardView):
registration.save()
if "voucher_code" in cleaned_data:
if cleaned_data_financial["voucher_code"]:
vouchers = Voucher.objects.filter(
person=person, event=event, used=False, code=cleaned_data["voucher_code"]
person=person, event=event, used=False, code=cleaned_data_financial["voucher_code"]
)
if vouchers:
voucher = vouchers.first()
@@ -646,7 +652,7 @@ class RegisterEventWizardView(SessionWizardView):
messages.error(self.request, _("You entered an invalid voucher code!"))
invoice = registration.get_invoice()
invoice.variant = cleaned_data["payment_method"]
invoice.variant = cleaned_data_financial["payment_method"]
invoice.save()
context = {}
Loading