# -*- coding: utf-8 -*-
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.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
email_field = 'email'
agree_newsletter = BooleanField(
required=False, initial=False, label=_(u'I want to receive Wolne Lektury\'s newsletter.'))
+ mailing = False
+ mailing_field = 'agree_newsletter'
data_processing_part1 = u'''\
Administratorem danych osobowych jest Fundacja Nowoczesna Polska (ul. Marszałkowska 84/92 lok. 125, 00-514 Warszawa).
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
- super(NewsletterForm, self).save()
+ super(NewsletterForm, self).save(*args, **kwargs)
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:
# send_noreply_mail(
# ugettext(u'Confirm your subscription to Wolne Lektury newsletter'),
# 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):
+ mailing = True
+ agree_newsletter = None
+
email = EmailField(label=_('email address'))
+ mailing_lists = MultipleChoiceField(
+ widget=CheckboxSelectMultiple,
+ choices=(('general', _(u'general newsletter')), ('contest', _(u'about the contest'))),
+ label=_(u'mailing list'))
def __init__(self, *args, **kwargs):
super(SubscribeForm, self).__init__(*args, **kwargs)
- self.fields['agree_newsletter'].required = True
class UnsubscribeForm(Form):