from hashlib import md5
-import requests
from django.conf import settings
from mailchimp3 import MailChimp
from mailchimp3.mailchimpclient import MailChimpError
-INTERESTS = {settings.MAILCHIMP_GROUP_ID: True}
-
-
-def get_client():
- headers = requests.utils.default_headers()
- headers['User-Agent'] = '%s (%s)' % settings.MANAGERS[0]
-
def subscriber_hash(email):
return md5(email).hexdigest()
data={'interests': interests})
-def subscribe(email):
+def subscribe(email, mailing_lists=None):
client = MailChimp(mc_api=settings.MAILCHIMP_API_KEY, timeout=10.0)
try:
member = client.lists.members.get(settings.MAILCHIMP_LIST_ID, subscriber_hash(email))
else:
if member['status'] != 'subscribed':
remove_from_groups(email, client)
+ mailing_lists = mailing_lists or [settings.MAILCHIMP_DEFAULT_GROUP]
+ interests = {
+ settings.MAILCHIMP_GROUP_IDS[mailing_list]: True
+ for mailing_list in mailing_lists
+ if mailing_list in settings.MAILCHIMP_GROUP_IDS
+ }
client.lists.members.create_or_update(
settings.MAILCHIMP_LIST_ID, subscriber_hash(email),
data={
'email_address': email,
'status_if_new': 'subscribed',
'status': 'subscribed',
- 'interests': INTERESTS,
+ 'interests': interests,
}
)
# -*- 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).
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):
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2018-04-04 17:12+0200\n"
+"POT-Creation-Date: 2018-09-28 11:23+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
-#: forms.py:17
+#: forms.py:19
msgid "I want to receive Wolne Lektury's newsletter."
msgstr ""
-#: forms.py:46 forms.py:54 models.py:10
+#: forms.py:60 forms.py:71 models.py:10
msgid "email address"
msgstr ""
-#: forms.py:61
+#: forms.py:63
+msgid "general newsletter"
+msgstr ""
+
+#: forms.py:63
+msgid "about the contest"
+msgstr ""
+
+#: forms.py:64
+msgid "mailing list"
+msgstr ""
+
+#: forms.py:78
msgid "Email address not found."
msgstr ""
-#: forms.py:72
+#: forms.py:89
msgid "Unsubscribe from Wolne Lektury's newsletter."
msgstr ""
msgid "Your subscription to Wolne Lektury newsletter is confirmed. Thank you!"
msgstr ""
-#: templates/newsletter/subscribe_form.html:15
+#: templates/newsletter/subscribe_form.html:16
msgid "Subscribe"
msgstr ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2018-04-04 17:12+0200\n"
+"POT-Creation-Date: 2018-09-28 11:23+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
-#: forms.py:17
+#: forms.py:19
msgid "I want to receive Wolne Lektury's newsletter."
msgstr ""
-#: forms.py:46 forms.py:54 models.py:10
+#: forms.py:60 forms.py:71 models.py:10
msgid "email address"
msgstr ""
-#: forms.py:61
+#: forms.py:63
+msgid "general newsletter"
+msgstr ""
+
+#: forms.py:63
+msgid "about the contest"
+msgstr ""
+
+#: forms.py:64
+msgid "mailing list"
+msgstr ""
+
+#: forms.py:78
msgid "Email address not found."
msgstr ""
-#: forms.py:72
+#: forms.py:89
msgid "Unsubscribe from Wolne Lektury's newsletter."
msgstr ""
msgid "Your subscription to Wolne Lektury newsletter is confirmed. Thank you!"
msgstr ""
-#: templates/newsletter/subscribe_form.html:15
+#: templates/newsletter/subscribe_form.html:16
msgid "Subscribe"
msgstr ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2018-04-04 17:12+0200\n"
+"POT-Creation-Date: 2018-09-28 11:23+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
-#: forms.py:17
+#: forms.py:19
msgid "I want to receive Wolne Lektury's newsletter."
msgstr ""
-#: forms.py:46 forms.py:54 models.py:10
+#: forms.py:60 forms.py:71 models.py:10
msgid "email address"
msgstr ""
-#: forms.py:61
+#: forms.py:63
+msgid "general newsletter"
+msgstr ""
+
+#: forms.py:63
+msgid "about the contest"
+msgstr ""
+
+#: forms.py:64
+msgid "mailing list"
+msgstr ""
+
+#: forms.py:78
msgid "Email address not found."
msgstr ""
-#: forms.py:72
+#: forms.py:89
msgid "Unsubscribe from Wolne Lektury's newsletter."
msgstr ""
msgid "Your subscription to Wolne Lektury newsletter is confirmed. Thank you!"
msgstr ""
-#: templates/newsletter/subscribe_form.html:15
+#: templates/newsletter/subscribe_form.html:16
msgid "Subscribe"
msgstr ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2018-04-04 17:12+0200\n"
+"POT-Creation-Date: 2018-09-28 11:23+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
-#: forms.py:17
+#: forms.py:19
msgid "I want to receive Wolne Lektury's newsletter."
msgstr ""
-#: forms.py:46 forms.py:54 models.py:10
+#: forms.py:60 forms.py:71 models.py:10
msgid "email address"
msgstr ""
-#: forms.py:61
+#: forms.py:63
+msgid "general newsletter"
+msgstr ""
+
+#: forms.py:63
+msgid "about the contest"
+msgstr ""
+
+#: forms.py:64
+msgid "mailing list"
+msgstr ""
+
+#: forms.py:78
msgid "Email address not found."
msgstr ""
-#: forms.py:72
+#: forms.py:89
msgid "Unsubscribe from Wolne Lektury's newsletter."
msgstr ""
msgid "Your subscription to Wolne Lektury newsletter is confirmed. Thank you!"
msgstr ""
-#: templates/newsletter/subscribe_form.html:15
+#: templates/newsletter/subscribe_form.html:16
msgid "Subscribe"
msgstr ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2018-04-04 17:12+0200\n"
+"POT-Creation-Date: 2018-09-28 11:23+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
-#: forms.py:17
+#: forms.py:19
msgid "I want to receive Wolne Lektury's newsletter."
msgstr ""
-#: forms.py:46 forms.py:54 models.py:10
+#: forms.py:60 forms.py:71 models.py:10
msgid "email address"
msgstr ""
-#: forms.py:61
+#: forms.py:63
+msgid "general newsletter"
+msgstr ""
+
+#: forms.py:63
+msgid "about the contest"
+msgstr ""
+
+#: forms.py:64
+msgid "mailing list"
+msgstr ""
+
+#: forms.py:78
msgid "Email address not found."
msgstr ""
-#: forms.py:72
+#: forms.py:89
msgid "Unsubscribe from Wolne Lektury's newsletter."
msgstr ""
msgid "Your subscription to Wolne Lektury newsletter is confirmed. Thank you!"
msgstr ""
-#: templates/newsletter/subscribe_form.html:15
+#: templates/newsletter/subscribe_form.html:16
msgid "Subscribe"
msgstr ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2018-04-04 17:12+0200\n"
+"POT-Creation-Date: 2018-09-28 11:23+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n"
"%100<10 || n%100>=20) ? 1 : 2);\n"
-#: forms.py:17
+#: forms.py:19
msgid "I want to receive Wolne Lektury's newsletter."
msgstr ""
-#: forms.py:46 forms.py:54 models.py:10
+#: forms.py:60 forms.py:71 models.py:10
msgid "email address"
msgstr ""
-#: forms.py:61
+#: forms.py:63
+msgid "general newsletter"
+msgstr ""
+
+#: forms.py:63
+msgid "about the contest"
+msgstr ""
+
+#: forms.py:64
+msgid "mailing list"
+msgstr ""
+
+#: forms.py:78
msgid "Email address not found."
msgstr ""
-#: forms.py:72
+#: forms.py:89
msgid "Unsubscribe from Wolne Lektury's newsletter."
msgstr ""
msgid "Your subscription to Wolne Lektury newsletter is confirmed. Thank you!"
msgstr ""
-#: templates/newsletter/subscribe_form.html:15
+#: templates/newsletter/subscribe_form.html:16
msgid "Subscribe"
msgstr ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2018-04-04 17:12+0200\n"
+"POT-Creation-Date: 2018-09-28 11:23+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Jan Szejko <jan.szejko@nowoczesnapolska.org.pl>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
"|| n%100>=20) ? 1 : 2);\n"
-#: forms.py:17
+#: forms.py:19
msgid "I want to receive Wolne Lektury's newsletter."
msgstr "Chcę otrzymywać newsletter Wolnych Lektur"
-#: forms.py:46 forms.py:54 models.py:10
+#: forms.py:60 forms.py:71 models.py:10
msgid "email address"
msgstr "adres email"
-#: forms.py:61
+#: forms.py:63
+msgid "general newsletter"
+msgstr "ogólny newsletter"
+
+#: forms.py:63
+msgid "about the contest"
+msgstr "informacje o konkursie"
+
+#: forms.py:64
+msgid "mailing list"
+msgstr "lista mailowa"
+
+#: forms.py:78
msgid "Email address not found."
msgstr "Nie znaleziono adresu email."
-#: forms.py:72
+#: forms.py:89
msgid "Unsubscribe from Wolne Lektury's newsletter."
msgstr "Wypisuję się z newslettera Wolnych Lektur"
msgid "Your subscription to Wolne Lektury newsletter is confirmed. Thank you!"
msgstr "Potwierdzono subskrypcję newslettera Wolnych Lektur. Dziękujemy!"
-#: templates/newsletter/subscribe_form.html:15
+#: templates/newsletter/subscribe_form.html:16
msgid "Subscribe"
msgstr "Zapisz się"
msgstr "Zapisz się na newsletter"
#: views.py:28
-#| msgid "Subscribe"
msgid "Subscribed"
msgstr "Zapisano do newslettera"
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2018-04-04 17:12+0200\n"
+"POT-Creation-Date: 2018-09-28 11:23+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
-#: forms.py:17
+#: forms.py:19
msgid "I want to receive Wolne Lektury's newsletter."
msgstr ""
-#: forms.py:46 forms.py:54 models.py:10
+#: forms.py:60 forms.py:71 models.py:10
msgid "email address"
msgstr ""
-#: forms.py:61
+#: forms.py:63
+msgid "general newsletter"
+msgstr ""
+
+#: forms.py:63
+msgid "about the contest"
+msgstr ""
+
+#: forms.py:64
+msgid "mailing list"
+msgstr ""
+
+#: forms.py:78
msgid "Email address not found."
msgstr ""
-#: forms.py:72
+#: forms.py:89
msgid "Unsubscribe from Wolne Lektury's newsletter."
msgstr ""
msgid "Your subscription to Wolne Lektury newsletter is confirmed. Thank you!"
msgstr ""
-#: templates/newsletter/subscribe_form.html:15
+#: templates/newsletter/subscribe_form.html:16
msgid "Subscribe"
msgstr ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2018-04-04 17:12+0200\n"
+"POT-Creation-Date: 2018-09-28 11:23+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
-#: forms.py:17
+#: forms.py:19
msgid "I want to receive Wolne Lektury's newsletter."
msgstr ""
-#: forms.py:46 forms.py:54 models.py:10
+#: forms.py:60 forms.py:71 models.py:10
msgid "email address"
msgstr ""
-#: forms.py:61
+#: forms.py:63
+msgid "general newsletter"
+msgstr ""
+
+#: forms.py:63
+msgid "about the contest"
+msgstr ""
+
+#: forms.py:64
+msgid "mailing list"
+msgstr ""
+
+#: forms.py:78
msgid "Email address not found."
msgstr ""
-#: forms.py:72
+#: forms.py:89
msgid "Unsubscribe from Wolne Lektury's newsletter."
msgstr ""
msgid "Your subscription to Wolne Lektury newsletter is confirmed. Thank you!"
msgstr ""
-#: templates/newsletter/subscribe_form.html:15
+#: templates/newsletter/subscribe_form.html:16
msgid "Subscribe"
msgstr ""
{% render_honeypot_field %}
<ol>
<li>{{ form.email|pretty_field }}</li>
- <li>{{ form.agree_newsletter|pretty_checkbox }}</li>
+ <li>{{ form.mailing_lists|pretty_field }}</li>
<li><span class="helptext">{{ form.data_processing }}</span></li>
<li><input type="submit" value="{% trans "Subscribe" %}"/></li>
</ol>