1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from django.core.exceptions import ValidationError
5 from django.core.validators import validate_email
6 from django.forms import Form, BooleanField
7 from django.forms.fields import EmailField
8 from django.utils.safestring import mark_safe
9 from django.utils.translation import gettext_lazy as _
10 from newsletter.subscribe import subscribe
11 from .models import Newsletter
14 class NewsletterForm(Form):
16 agree_newsletter = BooleanField(
17 required=False, initial=False, label=_('I want to receive Wolne Lektury\'s newsletter.'), label_suffix=False)
19 mailing_field = 'agree_newsletter'
22 data_processing_part1 = '''\
23 Administratorem danych osobowych jest Fundacja Nowoczesna Polska (ul. Marszałkowska 84/92 lok. 125, 00-514 Warszawa).
24 Podanie danych osobowych jest dobrowolne.'''
25 data_processing_part2 = '''Dane są przetwarzane w zakresie niezbędnym do wysyłania newslettera odbiorcom.'''
26 data_processing_part3 = '''\
27 Osobom, których dane są zbierane, przysługuje prawo dostępu do treści swoich danych oraz ich poprawiania.
28 Więcej informacji w <a href="https://nowoczesnapolska.org.pl/prywatnosc/">polityce prywatności.</a>'''
30 def __init__(self, *args, **kwargs):
31 super().__init__(*args, **kwargs)
32 # Move the newsletter field to the end.
33 f = self.fields['agree_newsletter']
34 del self.fields['agree_newsletter']
35 self.fields['agree_newsletter'] = f
38 def data_processing(self):
39 return mark_safe('%s %s %s' % (self.data_processing_part1, self.data_processing_part2, self.data_processing_part3))
41 def save(self, *args, **kwargs):
42 newsletter = self.newsletter or Newsletter.objects.filter(slug='').first()
46 if not (self.mailing or self.cleaned_data.get(self.mailing_field)):
48 email = self.cleaned_data[self.email_field]
51 except ValidationError:
54 subscribe(email, newsletter=newsletter)
57 class SubscribeForm(NewsletterForm):
59 agree_newsletter = None
60 required_css_class = 'required'
62 email = EmailField(label=_('email address'))
64 def __init__(self, newsletter, *args, **kwargs):
65 self.newsletter = newsletter
66 super(SubscribeForm, self).__init__(*args, **kwargs)