f8927e5b8c6f53c5e2123b770841be1d5d3bb1f4
[wolnelektury.git] / src / newsletter / forms.py
1 # -*- coding: utf-8 -*-
2
3 from django.forms import Form, BooleanField
4 from django.utils.translation import ugettext_lazy as _
5
6 from newsletter.models import Subscription
7
8
9 class NewsletterForm(Form):
10     email_field = 'email'
11     agree_newsletter = BooleanField(required=False, label=_(u'I want to receive Wolne Lektury\'s newsletter.'))
12
13     def save(self):
14         try:
15             # multiple inheritance mode
16             super(NewsletterForm, self).save()
17         except AttributeError:
18             pass
19         email = self.cleaned_data[self.email_field]
20         subscription, created = Subscription.objects.get_or_create(email=email)
21         if not created and not subscription.active:
22             subscription.active = True
23             subscription.save()
24         # Send some test email?