1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from django.http import Http404
5 from django.http.response import HttpResponseRedirect
6 from django.shortcuts import render, get_object_or_404
7 from django.urls import reverse
8 from django.utils.translation import ugettext_lazy as _
10 from newsletter.forms import UnsubscribeForm, SubscribeForm
11 from newsletter.models import Subscription
14 def subscribe_form(request):
16 form = SubscribeForm(request.POST)
19 return HttpResponseRedirect(reverse('subscribed'))
21 form = SubscribeForm()
22 return render(request, 'newsletter/subscribe_form.html', {
23 'page_title': _('Subscribe To Newsletter'),
28 def subscribed(request):
29 return render(request, 'newsletter/subscribed.html', {
30 'page_title': _('Subscribed'),
34 def check_subscription(subscription, hashcode):
35 if hashcode != subscription.hashcode():
39 def confirm_subscription(request, subscription_id, hashcode):
40 subscription = get_object_or_404(Subscription, id=subscription_id)
41 check_subscription(subscription, hashcode)
42 subscription.active = True
44 return render(request, 'newsletter/confirm_subscription.html', {
45 'page_title': _('Subscription confirmed')
49 def unsubscribe_form(request):
51 form = UnsubscribeForm(request.POST)
54 return HttpResponseRedirect(reverse('unsubscribed'))
56 form = UnsubscribeForm()
57 return render(request, 'newsletter/unsubscribe_form.html', {
58 'page_title': _('Unsubscribe'),
63 def unsubscribed(request):
64 return render(request, 'newsletter/unsubscribed.html', {
65 'page_title': _('Unsubscribed'),