fnp
/
wolnelektury.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Django 2.2
[wolnelektury.git]
/
src
/
newsletter
/
forms.py
diff --git
a/src/newsletter/forms.py
b/src/newsletter/forms.py
index
323fe3f
..
1091ed8
100644
(file)
--- a/
src/newsletter/forms.py
+++ b/
src/newsletter/forms.py
@@
-1,8
+1,11
@@
-# -*- coding: utf-8 -*-
+# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
from django.core.exceptions import ValidationError
from django.core.validators import validate_email
from django.core.exceptions import ValidationError
from django.core.validators import validate_email
-from django.forms import Form, BooleanField
+from django.forms import Form, BooleanField
, MultipleChoiceField
from django.forms.fields import EmailField
from django.forms.fields import EmailField
+from django.forms.widgets import CheckboxSelectMultiple
from django.template.loader import render_to_string
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _, ugettext
from django.template.loader import render_to_string
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _, ugettext
@@
-15,13
+18,15
@@
from wolnelektury.utils import send_noreply_mail
class NewsletterForm(Form):
email_field = 'email'
agree_newsletter = BooleanField(
class NewsletterForm(Form):
email_field = 'email'
agree_newsletter = BooleanField(
- required=False, initial=False, label=_(u'I want to receive Wolne Lektury\'s newsletter.'))
+ required=False, initial=False, label=_('I want to receive Wolne Lektury\'s newsletter.'))
+ mailing = False
+ mailing_field = 'agree_newsletter'
- data_processing_part1 =
u
'''\
+ data_processing_part1 = '''\
Administratorem danych osobowych jest Fundacja Nowoczesna Polska (ul. Marszałkowska 84/92 lok. 125, 00-514 Warszawa).
Podanie danych osobowych jest dobrowolne.'''
Administratorem danych osobowych jest Fundacja Nowoczesna Polska (ul. Marszałkowska 84/92 lok. 125, 00-514 Warszawa).
Podanie danych osobowych jest dobrowolne.'''
- data_processing_part2 =
u
'''Dane są przetwarzane w zakresie niezbędnym do wysyłania newslettera odbiorcom.'''
- data_processing_part3 =
u
'''\
+ data_processing_part2 = '''Dane są przetwarzane w zakresie niezbędnym do wysyłania newslettera odbiorcom.'''
+ data_processing_part3 = '''\
Osobom, których dane są zbierane, przysługuje prawo dostępu do treści swoich danych oraz ich poprawiania.
Więcej informacji w <a href="">polityce prywatności.</a>'''
Osobom, których dane są zbierane, przysługuje prawo dostępu do treści swoich danych oraz ich poprawiania.
Więcej informacji w <a href="">polityce prywatności.</a>'''
@@
-29,13
+34,13
@@
Więcej informacji w <a href="">polityce prywatności.</a>'''
def data_processing(self):
return mark_safe('%s %s %s' % (self.data_processing_part1, self.data_processing_part2, self.data_processing_part3))
def data_processing(self):
return mark_safe('%s %s %s' % (self.data_processing_part1, self.data_processing_part2, self.data_processing_part3))
- def save(self):
+ def save(self
, *args, **kwargs
):
try:
# multiple inheritance mode
try:
# multiple inheritance mode
- super(NewsletterForm, self).save()
+ super(NewsletterForm, self).save(
*args, **kwargs
)
except AttributeError:
pass
except AttributeError:
pass
- if not
self.cleaned_data.get('agree_newsletter'
):
+ if not
(self.mailing or self.cleaned_data.get(self.mailing_field)
):
return
email = self.cleaned_data[self.email_field]
try:
return
email = self.cleaned_data[self.email_field]
try:
@@
-45,17
+50,23
@@
Więcej informacji w <a href="">polityce prywatności.</a>'''
else:
# subscription, created = Subscription.objects.get_or_create(email=email, defaults={'active': False})
# send_noreply_mail(
else:
# subscription, created = Subscription.objects.get_or_create(email=email, defaults={'active': False})
# send_noreply_mail(
- # ugettext(
u
'Confirm your subscription to Wolne Lektury newsletter'),
+ # ugettext('Confirm your subscription to Wolne Lektury newsletter'),
# render_to_string('newsletter/subscribe_email.html', {'subscription': subscription}), [email])
# render_to_string('newsletter/subscribe_email.html', {'subscription': subscription}), [email])
- mailing.subscribe(email)
+ mailing.subscribe(email
, mailing_lists=self.cleaned_data.get('mailing_lists')
)
class SubscribeForm(NewsletterForm):
class SubscribeForm(NewsletterForm):
+ mailing = True
+ agree_newsletter = None
+
email = EmailField(label=_('email address'))
email = EmailField(label=_('email address'))
+ mailing_lists = MultipleChoiceField(
+ widget=CheckboxSelectMultiple,
+ choices=(('general', _('general newsletter')), ('contest', _('about the contest'))),
+ label=_('mailing list'))
def __init__(self, *args, **kwargs):
super(SubscribeForm, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs):
super(SubscribeForm, self).__init__(*args, **kwargs)
- self.fields['agree_newsletter'].required = True
class UnsubscribeForm(Form):
class UnsubscribeForm(Form):
@@
-66,17
+77,18
@@
class UnsubscribeForm(Form):
try:
subscription = Subscription.objects.get(email=email)
except Subscription.DoesNotExist:
try:
subscription = Subscription.objects.get(email=email)
except Subscription.DoesNotExist:
- raise ValidationError(ugettext(
u
'Email address not found.'))
+ raise ValidationError(ugettext('Email address not found.'))
self.cleaned_data['subscription'] = subscription
def save(self):
subscription = self.cleaned_data['subscription']
subscription.active = False
subscription.save()
self.cleaned_data['subscription'] = subscription
def save(self):
subscription = self.cleaned_data['subscription']
subscription.active = False
subscription.save()
+ mailing.unsubscribe(subscription.email)
context = {'subscription': subscription}
# refactor to send_noreply_mail
send_noreply_mail(
context = {'subscription': subscription}
# refactor to send_noreply_mail
send_noreply_mail(
- ugettext(
u
'Unsubscribe from Wolne Lektury\'s newsletter.'),
+ ugettext('Unsubscribe from Wolne Lektury\'s newsletter.'),
render_to_string('newsletter/unsubscribe_email.html', context),
[subscription.email], fail_silently=True)
render_to_string('newsletter/unsubscribe_email.html', context),
[subscription.email], fail_silently=True)