1 # -*- coding: utf-8 -*-
2 from django.core.exceptions import ValidationError
3 from django.core.validators import validate_email
4 from django.forms import Form, BooleanField
5 from django.utils.translation import ugettext_lazy as _
7 from newsletter.models import Subscription
10 class NewsletterForm(Form):
12 agree_newsletter = BooleanField(
13 required=False, initial=True, label=_(u'I want to receive Wolne Lektury\'s newsletter.'))
17 # multiple inheritance mode
18 super(NewsletterForm, self).save()
19 except AttributeError:
21 if not self.cleaned_data.get('agree_newsletter'):
23 email = self.cleaned_data[self.email_field]
26 except ValidationError:
29 subscription, created = Subscription.objects.get_or_create(email=email)
30 if not created and not subscription.active:
31 subscription.active = True
33 # Send some test email?