From e24eb8ce3746e33f3a446658fb022ff21c2a4cb9 Mon Sep 17 00:00:00 2001 From: klmp200 Date: Tue, 16 Oct 2018 00:44:32 +0200 Subject: [PATCH] subscriptions: add date_of_birth for new users created in subscription form --- subscription/templates/subscription/subscription.jinja | 1 + subscription/views.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/subscription/templates/subscription/subscription.jinja b/subscription/templates/subscription/subscription.jinja index e48bed4d..7c0fc470 100644 --- a/subscription/templates/subscription/subscription.jinja +++ b/subscription/templates/subscription/subscription.jinja @@ -15,6 +15,7 @@

{{ form.first_name.errors }} {{ form.first_name }}

{{ form.last_name.errors }} {{ form.last_name }}

{{ form.email.errors }} {{ form.email }}

+

{{ form.date_of_birth.errors }} {{ form.date_of_birth }}

{{ form.subscription_type.errors }} {{ form.subscription_type }}

{{ form.payment_method.errors }} {{ diff --git a/subscription/views.py b/subscription/views.py index 81e1c921..0d91c6be 100644 --- a/subscription/views.py +++ b/subscription/views.py @@ -35,6 +35,7 @@ import random from subscription.models import Subscription from core.views.forms import SelectDateTime from core.models import User +from core.views.forms import SelectDate class SelectionDateForm(forms.Form): @@ -71,6 +72,7 @@ class SubscriptionForm(forms.ModelForm): max_length=User._meta.get_field("first_name").max_length ) self.fields["email"] = forms.EmailField() + self.fields["date_of_birth"] = forms.DateTimeField(widget=SelectDate) self.fields.move_to_end("subscription_type") self.fields.move_to_end("payment_method") self.fields.move_to_end("location") @@ -88,6 +90,7 @@ class SubscriptionForm(forms.ModelForm): and "last_name" not in self.errors.as_data() and "first_name" not in self.errors.as_data() and "email" not in self.errors.as_data() + and "date_of_birth" not in self.errors.as_data() ): self.errors.pop("member", None) if self.errors: @@ -102,6 +105,7 @@ class SubscriptionForm(forms.ModelForm): last_name=self.cleaned_data.get("last_name"), first_name=self.cleaned_data.get("first_name"), email=self.cleaned_data.get("email"), + date_of_birth=self.cleaned_data.get("date_of_birth"), ) u.generate_username() u.set_password(str(random.randrange(1000000, 10000000))) @@ -111,6 +115,7 @@ class SubscriptionForm(forms.ModelForm): self.errors.pop("last_name", None) self.errors.pop("first_name", None) self.errors.pop("email", None) + self.errors.pop("date_of_birth", None) if cleaned_data.get("member") is None: # This should be handled here, but it is done in the Subscription model's clean method # TODO investigate why!