Remove legacy search.
[wolnelektury.git] / src / club / forms.py
index fe38c7b..098a70e 100644 (file)
@@ -3,7 +3,7 @@
 #
 from decimal import Decimal
 from django import forms
-from django.utils.translation import ugettext as _
+from django.utils.translation import gettext as _
 from newsletter.forms import NewsletterForm
 from . import models, payment_methods
 from .payu.forms import CardTokenForm
@@ -12,7 +12,7 @@ from .payu.forms import CardTokenForm
 class ScheduleForm(forms.ModelForm, NewsletterForm):
     data_processing = '''Informacja o przetwarzaniu danych osobowych
 
-<div class='more-expand'>Administratorem Twoich danych osobowych jest Fundacja Nowoczesna Polska z siedzibą w Warszawie, przy ul. Marszałkowskiej 84/92 lok.125, 00-514 Warszawa (dalej: Fundacja).
+<div class='more-expand'>Administratorem Twoich danych osobowych jest Fundacja Wolne Lektury z siedzibą w Warszawie, przy ul. Marszałkowskiej 84/92 lok.125, 00-514 Warszawa (dalej: Fundacja).
 
 Z Fundacją można się kontaktować we wszystkich sprawach dotyczących przetwarzania danych osobowych oraz korzystania z praw związanych z przetwarzaniem danych, w szczególności w zakresie wycofania udzielonej zgody na przetwarzanie danych poprzez adres e-mail fundacja@nowoczesnapolska.org.pl, telefonicznie pod numerem +48 22 621 30 17 (w dni powszednie w godz. 9-17) lub listownie pisząc na adres siedziby Fundacji.
 Podanie danych osobowych jest dobrowolne, jednak konieczne do przeprowadzenia płatności oraz realizacji innych celów wskazanych poniżej.
@@ -52,7 +52,7 @@ Twoje dane osobowe nie będą profilowane, ani przesyłane do państw trzecich i
             'first_name': forms.TextInput(attrs={"placeholder": _('first name')}),
             'last_name': forms.TextInput(attrs={"placeholder": _('last name')}),
 
-            'postal': forms.Textarea(attrs={"placeholder": _("If you leave your address, we'll be able to send you a postcard and other gadgets.")}),
+            'postal': forms.Textarea(attrs={"placeholder": _("street address")}),
             'postal_code': forms.TextInput(attrs={"placeholder": _('postal code')}),
             'postal_town': forms.TextInput(attrs={"placeholder": _('town')}),
         }
@@ -115,3 +115,89 @@ Twoje dane osobowe nie będą profilowane, ani przesyłane do państw trzecich i
 class PayUCardTokenForm(CardTokenForm):
     def get_queryset(self, view):
         return view.get_schedule().payucardtoken_set
+
+
+
+class DonationStep1Form(forms.ModelForm):
+    switch = forms.CharField()
+    single_amount = forms.IntegerField(required=False)
+    monthly_amount = forms.IntegerField(required=False)
+    single_amount_selected = forms.IntegerField(required=False)
+    monthly_amount_selected = forms.IntegerField(required=False)
+    custom_amount = forms.IntegerField(required=False)
+
+    amount = forms.IntegerField(required=False) # hidden
+
+    class Meta:
+        model = models.Schedule
+        fields = [
+            'amount',
+            'monthly'
+            ]
+
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+        club = models.Club.objects.first()
+        if club is not None:
+            self.fields['custom_amount'].widget.attrs['min'] = club.min_amount
+
+    def clean(self):
+        state = {}
+        state['monthly'] = self.cleaned_data['switch'] == 'monthly'
+        which = 'monthly' if state['monthly'] else 'single'
+        state['amount'] = \
+            self.cleaned_data[f'{which}_amount'] or \
+            self.cleaned_data['custom_amount'] or \
+            self.cleaned_data[f'{which}_amount_selected']
+
+        return state
+
+
+
+class DonationStep2Form(forms.ModelForm, NewsletterForm):
+    class Meta:
+        model = models.Schedule
+        fields = [
+            'first_name', 'last_name',
+            'email', 'phone',
+            'postal',
+            'postal_code', 'postal_town', 'postal_country',
+            ]
+        widgets = {
+            'amount': forms.HiddenInput,
+            'monthly': forms.HiddenInput,
+        }
+    
+    def __init__(self, referer=None, **kwargs):
+        self.referer = referer
+        super().__init__(**kwargs)
+
+        self.fields['first_name'].required = True
+        self.fields['last_name'].required = True
+        self.fields['phone'].required = True
+        
+        self.consent = []
+        for c in models.Consent.objects.filter(active=True).order_by('order'):
+            key = f'consent{c.id}'
+            self.fields[key] = forms.BooleanField(
+                label=c.text,
+                required=c.required
+            )
+            self.consent.append((
+                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 = []
+        for consent, key, consent_field in self.consent:
+            if self.cleaned_data[key]:
+                instance.consent.add(consent)
+
+        return instance
+