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 if 'agree_newsletter' in self.fields:
34 f = self.fields['agree_newsletter']
35 del self.fields['agree_newsletter']
36 self.fields['agree_newsletter'] = f
39 def data_processing(self):
40 return mark_safe('%s %s %s' % (self.data_processing_part1, self.data_processing_part2, self.data_processing_part3))
42 def save(self, *args, **kwargs):
43 newsletter = self.newsletter or Newsletter.objects.filter(slug='').first()
47 if not (self.mailing or self.cleaned_data.get(self.mailing_field)):
49 email = self.cleaned_data[self.email_field]
52 except ValidationError:
55 subscribe(email, newsletter=newsletter)
58 class SubscribeForm(NewsletterForm):
60 agree_newsletter = None
61 required_css_class = 'required'
63 email = EmailField(label=_('email address'))
65 def __init__(self, newsletter, *args, **kwargs):
66 self.newsletter = newsletter
67 super(SubscribeForm, self).__init__(*args, **kwargs)