<li>
<span class="error">%(errors)s</span>
<label class="nohide"><span class="label">%(label)s: </span>%(input)s</label>
+ <span class="helptext">%(helptext)s</span>
</li>'''
- return mark_safe(template % {'errors': field.errors, 'input': field, 'label': field.label})
+ return mark_safe(template % {
+ 'errors': field.errors,
+ 'input': field,
+ 'label': field.label,
+ 'helptext': field.help_text,
+ })
@register.filter
<li class="checkbox">
<span class="error">%(errors)s</span>
<label class="nohide">%(input)s<span class="label"> %(label)s</span></label>
+ <span class="helptext">%(helptext)s</span>
</li>''')
return my_urls + urls
def extract_subscribers(self, request):
- return HttpResponse(',\n'.join(Subscription.objects.values_list('email', flat=True)), content_type='text/plain')
+ active_subscriptions = Subscription.objects.filter(active=True)
+ return HttpResponse(',\n'.join(active_subscriptions.values_list('email', flat=True)),
+ content_type='text/plain')
admin.site.register(Subscription, SubscriptionAdmin)
from django.core.exceptions import ValidationError
from django.core.validators import validate_email
from django.forms import Form, BooleanField
-from django.utils.translation import ugettext_lazy as _
+from django.forms.fields import EmailField
+from django.template.loader import render_to_string
+from django.utils.translation import ugettext_lazy as _, ugettext
from newsletter.models import Subscription
+from wolnelektury.utils import send_noreply_mail
class NewsletterForm(Form):
email_field = 'email'
agree_newsletter = BooleanField(
- required=False, initial=True, label=_(u'I want to receive Wolne Lektury\'s newsletter.'))
+ required=False, initial=True, label=_(u'I want to receive Wolne Lektury\'s newsletter.'), help_text='''\
+Oświadczam, że wyrażam zgodę na przetwarzanie moich danych osobowych zawartych \
+w niniejszym formularzu zgłoszeniowym przez Fundację Nowoczesna Polska (administratora danych) z siedzibą \
+w Warszawie (00-514) przy ul. Marszałkowskiej 84/92 lok. 125 w celu otrzymywania newslettera Wolnych Lektur. \
+Jednocześnie oświadczam, że zostałam/em poinformowana/y o tym, że mam prawo wglądu w treść swoich danych i \
+możliwość ich poprawiania oraz że ich podanie jest dobrowolne, ale niezbędne do dokonania zgłoszenia.''')
def save(self):
try:
except ValidationError:
pass
else:
- subscription, created = Subscription.objects.get_or_create(email=email)
- if not created and not subscription.active:
- subscription.active = True
- subscription.save()
- # Send some test email?
+ subscription, created = Subscription.objects.get_or_create(email=email, defaults={'active': False})
+ send_noreply_mail(
+ ugettext(u'Confirm your subscription to Wolne Lektury newsletter'),
+ render_to_string('newsletter/subscribe_email.html', {'subscription': subscription}), [email])
+
+
+class SubscribeForm(NewsletterForm):
+ email = EmailField(label=_('email address'))
+
+ def __init__(self, *args, **kwargs):
+ super(SubscribeForm, self).__init__(*args, **kwargs)
+ self.fields['agree_newsletter'].required = True
+
+
+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(u'Email address not found.'))
+ self.cleaned_data['subscription'] = subscription
+
+ def save(self):
+ subscription = self.cleaned_data['subscription']
+ subscription.active = False
+ subscription.save()
+
+ context = {'subscription': subscription}
+ # refactor to send_noreply_mail
+ send_noreply_mail(
+ ugettext(u'Unsubscribe from Wolne Lektury\'s newsletter.'),
+ render_to_string('newsletter/unsubscribe_email.html', context),
+ [subscription.email], fail_silently=True)
# -*- coding: utf-8 -*-
+import hashlib
+
from django.db.models import Model, EmailField, DateTimeField, BooleanField
from django.utils.translation import ugettext_lazy as _
+from django.conf import settings
class Subscription(Model):
verbose_name_plural = _('subscriptions')
def __unicode__(self):
- return self.email
\ No newline at end of file
+ return self.email
+
+ def hashcode(self):
+ return hashlib.sha224(self.email + settings.SECRET_KEY).hexdigest()[:30]
--- /dev/null
+{% extends "base/base.html" %}
+{% load i18n %}
+
+{% block body %}
+ <h1>{{ page_title }}</h1>
+ <p>{% trans "Your subscription to Wolne Lektury newsletter is confirmed. Thank you!" %}</p>
+{% endblock %}
\ No newline at end of file
--- /dev/null
+Dziękujemy za zapisanie się na newsletter Wolnych Lektur!
+
+W celu dokończenia rejestracji kliknij w poniższy link:
+
+https://wolnelektury.pl{% url 'confirm_subscription' subscription_id=subscription.id hashcode=subscription.hashcode %}
+
+lub skopiuj go do swojej przeglądarki.
+
+Dopóki tego nie zrobisz, nie będziesz otrzymywał od nas newsletterów.
+
+Jeżeli jednak otrzymałaś/eś tę wiadomość przez przypadek i nie chcesz otrzymywać newslettera Wolnych Lektur, zignoruj ją.
+
+Pozdrawiamy,
+zespół Wolnych Lektur
\ No newline at end of file
--- /dev/null
+{% extends "base/base.html" %}
+{% load i18n %}
+{% load ssify %}
+{% load honeypot %}
+{% load ajaxable_tags %}
+
+{% block body %}
+ <h1>{{ page_title }}</h1>
+ <form id="subscribe-form" action="" method="post" accept-charset="utf-8" class="cuteform">
+ {% ssi_csrf_token %}
+ {% render_honeypot_field %}
+ <ol>
+ <li>{{ form.email|pretty_field }}</li>
+ <li>{{ form.agree_newsletter|pretty_checkbox }}</li>
+ <li><input type="submit" value="{% trans "Subscribe" %}"/></li>
+ </ol>
+ </form>
+{% endblock %}
\ No newline at end of file
--- /dev/null
+{% extends "base/base.html" %}
+{% load i18n %}
+
+{% block body %}
+ <h1>{{ page_title }}</h1>
+ <p>
+ {% trans "You have requested subscription to Wolne Lektury newsletter. You'll receive a confirmation link by email." %}
+ </p>
+{% endblock %}
\ No newline at end of file
--- /dev/null
+Dziękujemy za dotychczasowe korzystanie z newslettera Wolnych Lektur.
+Jeśli w przyszłości zdecydujesz ponownie się na niego zapisać, wypełnij formularz
+https://wolnelektury.pl/{% url "subscribe" %}, a będziemy Cię na bieżąco informować o naszych działaniach.
+
+Pozdrawiamy,
+zespół Wolnych Lektur
\ No newline at end of file
--- /dev/null
+{% extends "base/base.html" %}
+{% load i18n %}
+{% load ssify %}
+{% load honeypot %}
+
+{% block body %}
+ <h1>{{ page_title }}</h1>
+ <form id="unsubscribe-form" action="" method="post" accept-charset="utf-8" class="cuteform">
+ {% ssi_csrf_token %}
+ {% render_honeypot_field %}
+ <ol>
+ {{ form.as_ul }}
+ <li><input type="submit" value="{% trans "Unsubscribe" %}"/></li>
+ </ol>
+ </form>
+{% endblock %}
\ No newline at end of file
--- /dev/null
+{% extends "base/base.html" %}
+{% load i18n %}
+
+{% block body %}
+ <h1>{{ page_title }}</h1>
+ <p>{% trans "You have unsubscribed from Wolne Lektury newsletter. You'll receive a confirmation by email." %}</p>
+{% endblock %}
\ No newline at end of file
from . import views
urlpatterns = [
- url(r'^wypisz-sie/$', views.unsubscribe, name='unsubscribe'),
+ url(r'^zapisz-sie/$', views.subscribe_form, name='subscribe'),
+ url(r'^zapis/$', views.subscribed, name='subscribed'),
+ url(r'^potwierdzenie/(?P<subscription_id>[0-9]+)/(?P<hashcode>[0-9a-f]+)/$',
+ views.confirm_subscription, name='confirm_subscription'),
+ url(r'^wypisz-sie/$', views.unsubscribe_form, name='unsubscribe'),
+ url(r'^wypisano/$', views.unsubscribed, name='unsubscribed'),
]
# -*- coding: utf-8 -*-
-from django.shortcuts import render
+from django.core.urlresolvers import reverse
+from django.http import Http404
+from django.http.response import HttpResponseRedirect
+from django.shortcuts import render, get_object_or_404
from django.utils.translation import ugettext_lazy as _
+from newsletter.forms import UnsubscribeForm, SubscribeForm
+from newsletter.models import Subscription
-def unsubscribe(request):
- return render(request, 'newsletter/unsubscribe.html', {
+
+def subscribe_form(request):
+ if request.POST:
+ form = SubscribeForm(request.POST)
+ if form.is_valid():
+ form.save()
+ return HttpResponseRedirect(reverse('subscribed'))
+ else:
+ form = SubscribeForm()
+ return render(request, 'newsletter/subscribe_form.html', {
+ 'page_title': _(u'Subscribe'),
+ 'form': form,
+ })
+
+
+def subscribed(request):
+ return render(request, 'newsletter/subscribed.html', {
+ 'page_title': _(u'Subscribed'),
+ })
+
+
+def check_subscription(subscription, hashcode):
+ if hashcode != subscription.hashcode():
+ raise Http404
+
+
+def confirm_subscription(request, subscription_id, hashcode):
+ subscription = get_object_or_404(Subscription, id=subscription_id)
+ check_subscription(subscription, hashcode)
+ subscription.active = True
+ subscription.save()
+ return render(request, 'newsletter/confirm_subscription.html', {
+ 'page_title': _(u'Subscription confirmed')
+ })
+
+
+def unsubscribe_form(request):
+ if request.POST:
+ form = UnsubscribeForm(request.POST)
+ if form.is_valid():
+ form.save()
+ return HttpResponseRedirect(reverse('unsubscribed'))
+ else:
+ form = UnsubscribeForm()
+ return render(request, 'newsletter/unsubscribe_form.html', {
'page_title': _(u'Unsubscribe'),
+ 'form': form,
+ })
+
+
+def unsubscribed(request):
+ return render(request, 'newsletter/unsubscribed.html', {
+ 'page_title': _(u'Unsubscribed'),
})
\ No newline at end of file
from newsletter.forms import NewsletterForm
from suggest.models import PublishingSuggestion, Suggestion
+from wolnelektury.utils import send_noreply_mail
class SuggestForm(NewsletterForm):
except ValidationError:
pass
else:
- send_mail(u'[WolneLektury] ' + ugettext(u'Thank you for your suggestion.'),
- ugettext(u"""\
+ send_noreply_mail(
+ ugettext(u'Thank you for your suggestion.'),
+ ugettext(u"""\
Thank you for your comment on WolneLektury.pl.
-The suggestion has been referred to the project coordinator.""") +
- u'\n\n-- \n' + ugettext(u'''Message sent automatically. Please do not reply.'''),
- 'no-reply@wolnelektury.pl', [contact], fail_silently=True)
+The suggestion has been referred to the project coordinator."""),
+ [contact], fail_silently=True)
class PublishingSuggestForm(NewsletterForm):
pass
else:
send_mail(
- u'[WolneLektury] ' + ugettext(u'Thank you for your suggestion.'),
+ ugettext(u'Thank you for your suggestion.'),
ugettext(u"""\
Thank you for your comment on WolneLektury.pl.
-The suggestion has been referred to the project coordinator.""") +
- u"\n\n-- \n" + ugettext(u'''Message sent automatically. Please do not reply.'''),
- 'no-reply@wolnelektury.pl', [contact], fail_silently=True)
+The suggestion has been referred to the project coordinator."""),
+ [contact], fail_silently=True)
<li><a href="{% url 'oaipmh' %}">OAI-PMH</a></li>
<li><a href="{% url 'lesmianator' %}" lang="pl">Leśmianator</a></li>
<li><a href="http://polski.wolnelektury.pl" lang="pl">Materiały do nauki j. polskiego</a></li>
+ <li><a href="{% url 'subscribe' %}">{% trans "Newsletter" %}</a></li>
</ul>
</section>
import pytz
from inspect import getargspec
+from django.core.mail import send_mail
from django.http import HttpResponse
from django.template import RequestContext
from django.template.loader import render_to_string
from django.utils import timezone
from django.conf import settings
+from django.utils.translation import ugettext
tz = pytz.timezone(settings.TIME_ZONE)
return ajax_view
return decorator
+
+
+def send_noreply_mail(subject, message, recipient_list, **kwargs):
+ send_mail(
+ u'[WolneLektury] ' + subject,
+ message + u"\n\n-- \n" + ugettext(u'Message sent automatically. Please do not reply.'),
+ 'no-reply@wolnelektury.pl', recipient_list, **kwargs)