mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-28 20:14:23 +00:00
add initial values to forms
This commit is contained in:
parent
d0ed13cbc1
commit
670417bb2f
@ -23,6 +23,14 @@ class SelectionDateForm(forms.Form):
|
|||||||
|
|
||||||
|
|
||||||
class SubscriptionForm(forms.ModelForm):
|
class SubscriptionForm(forms.ModelForm):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
initial = kwargs.pop("initial", {})
|
||||||
|
if "subscription_type" not in initial:
|
||||||
|
initial["subscription_type"] = "deux-semestres"
|
||||||
|
if "payment_method" not in initial:
|
||||||
|
initial["payment_method"] = "CARD"
|
||||||
|
super().__init__(*args, initial=initial, **kwargs)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if self.errors:
|
if self.errors:
|
||||||
# let django deal with the error messages
|
# let django deal with the error messages
|
||||||
|
@ -39,7 +39,9 @@ class NewSubscription(CanCreateSubscriptionMixin, TemplateView):
|
|||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
return super().get_context_data(**kwargs) | {
|
return super().get_context_data(**kwargs) | {
|
||||||
"existing_user_form": SubscriptionExistingUserForm(),
|
"existing_user_form": SubscriptionExistingUserForm(
|
||||||
|
initial={"member": self.request.GET.get("member")}
|
||||||
|
),
|
||||||
"new_user_form": SubscriptionNewUserForm(),
|
"new_user_form": SubscriptionNewUserForm(),
|
||||||
"existing_user_post_url": reverse("subscription:fragment-existing-user"),
|
"existing_user_post_url": reverse("subscription:fragment-existing-user"),
|
||||||
"new_user_post_url": reverse("subscription:fragment-new-user"),
|
"new_user_post_url": reverse("subscription:fragment-new-user"),
|
||||||
|
Loading…
Reference in New Issue
Block a user