remember url on donation step 1
authorRadek Czajka <rczajka@rczajka.pl>
Fri, 6 Dec 2024 08:34:38 +0000 (09:34 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Fri, 6 Dec 2024 08:34:38 +0000 (09:34 +0100)
src/club/forms.py
src/club/views.py

index df92524..22b0554 100644 (file)
@@ -31,7 +31,8 @@ class DonationStep1Form(forms.ModelForm):
             'monthly'
             ]
 
-    def __init__(self, *args, **kwargs):
+    def __init__(self, *args, referer=None, **kwargs):
+        self.referer = referer
         super().__init__(*args, **kwargs)
         club = models.Club.objects.first()
         if club is not None:
@@ -48,6 +49,9 @@ class DonationStep1Form(forms.ModelForm):
 
         return state
 
+    def save(self, *args, **kwargs):
+        self.instance.source = self.referer
+        return super().save(*args, **kwargs)
 
 
 class DonationStep2Form(forms.ModelForm, NewsletterForm):
@@ -64,8 +68,7 @@ class DonationStep2Form(forms.ModelForm, NewsletterForm):
             'monthly': forms.HiddenInput,
         }
     
-    def __init__(self, referer=None, **kwargs):
-        self.referer = referer
+    def __init__(self, **kwargs):
         super().__init__(**kwargs)
 
         self.fields['first_name'].required = True
@@ -83,11 +86,8 @@ class DonationStep2Form(forms.ModelForm, NewsletterForm):
                 c, key, (lambda k: lambda: self[k])(key)
             ))
 
-
-
     def save(self, *args, **kwargs):
         NewsletterForm.save(self, *args, **kwargs)
-        self.instance.source = self.referer or ''
         instance = super().save(*args, **kwargs)
 
         consents = []
index 1ab1eae..c6136b6 100644 (file)
@@ -99,7 +99,7 @@ class JoinView(CreateView):
 
     def get_form_kwargs(self):
         kwargs = super().get_form_kwargs()
-        #kwargs['referer'] = self.request.META.get('HTTP_REFERER', '')
+        kwargs['referer'] = self.request.META.get('HTTP_REFERER', '')
         return kwargs
 
     def form_valid(self, form):