1 from django.http import Http404
2 from django.http.response import HttpResponseRedirect
3 from django.shortcuts import render, get_object_or_404
4 from django.urls import reverse
5 from django.utils.translation import ugettext_lazy as _
7 from newsletter.forms import UnsubscribeForm, SubscribeForm
8 from newsletter.models import Subscription
11 def subscribe_form(request):
13 form = SubscribeForm(request.POST)
16 return HttpResponseRedirect(reverse('subscribed'))
18 form = SubscribeForm()
19 return render(request, 'newsletter/subscribe_form.html', {
20 'page_title': _(u'Subscribe To Newsletter'),
25 def subscribed(request):
26 return render(request, 'newsletter/subscribed.html', {
27 'page_title': _(u'Subscribed'),
31 def check_subscription(subscription, hashcode):
32 if hashcode != subscription.hashcode():
36 def confirm_subscription(request, subscription_id, hashcode):
37 subscription = get_object_or_404(Subscription, id=subscription_id)
38 check_subscription(subscription, hashcode)
39 subscription.active = True
41 return render(request, 'newsletter/confirm_subscription.html', {
42 'page_title': _(u'Subscription confirmed')
46 def unsubscribe_form(request):
48 form = UnsubscribeForm(request.POST)
51 return HttpResponseRedirect(reverse('unsubscribed'))
53 form = UnsubscribeForm()
54 return render(request, 'newsletter/unsubscribe_form.html', {
55 'page_title': _(u'Unsubscribe'),
60 def unsubscribed(request):
61 return render(request, 'newsletter/unsubscribed.html', {
62 'page_title': _(u'Unsubscribed'),