From 670417bb2f7df336b047dc97fd66e8c998f12e19 Mon Sep 17 00:00:00 2001 From: imperosol Date: Thu, 28 Nov 2024 11:53:35 +0100 Subject: [PATCH] add initial values to forms --- subscription/forms.py | 8 ++++++++ subscription/views.py | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/subscription/forms.py b/subscription/forms.py index 7710825b..1f4c193d 100644 --- a/subscription/forms.py +++ b/subscription/forms.py @@ -23,6 +23,14 @@ class SelectionDateForm(forms.Form): 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): if self.errors: # let django deal with the error messages diff --git a/subscription/views.py b/subscription/views.py index 3e8cf0f1..2948391b 100644 --- a/subscription/views.py +++ b/subscription/views.py @@ -39,7 +39,9 @@ class NewSubscription(CanCreateSubscriptionMixin, TemplateView): def get_context_data(self, **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(), "existing_user_post_url": reverse("subscription:fragment-existing-user"), "new_user_post_url": reverse("subscription:fragment-new-user"),