+ try:
+ validate_email(email)
+ except ValidationError:
+ pass
+ else:
+ # subscription, created = Subscription.objects.get_or_create(email=email, defaults={'active': False})
+ # send_noreply_mail(
+ # ugettext('Confirm your subscription to Wolne Lektury newsletter'),
+ # render_to_string('newsletter/subscribe_email.html', {'subscription': subscription}), [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', _('general newsletter')), ('contest', _('about the contest'))),
+ label=_('mailing list'))
+
+ def __init__(self, *args, **kwargs):
+ super(SubscribeForm, self).__init__(*args, **kwargs)
+
+
+class UnsubscribeForm(Form):
+ email = EmailField(label=_('email address'))
+
+ def clean(self):
+ email = self.cleaned_data.get('email')
+ try:
+ subscription = Subscription.objects.get(email=email)
+ except Subscription.DoesNotExist:
+ 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()
+ mailing.unsubscribe(subscription.email)
+
+ context = {'subscription': subscription}
+ # refactor to send_noreply_mail
+ send_noreply_mail(
+ ugettext('Unsubscribe from Wolne Lektury\'s newsletter.'),
+ render_to_string('newsletter/unsubscribe_email.html', context),
+ [subscription.email], fail_silently=True)