1 # -*- coding: utf-8 -*-
2 from django.core.urlresolvers import reverse
3 from django.http import Http404
4 from django.http.response import HttpResponseRedirect
5 from django.shortcuts import render, get_object_or_404
6 from django.utils.translation import ugettext_lazy as _
8 from newsletter.forms import UnsubscribeForm, SubscribeForm
9 from newsletter.models import Subscription
12 def subscribe_form(request):
14 form = SubscribeForm(request.POST)
17 return HttpResponseRedirect(reverse('subscribed'))
19 form = SubscribeForm()
20 return render(request, 'newsletter/subscribe_form.html', {
21 'page_title': _(u'Subscribe'),
26 def subscribed(request):
27 return render(request, 'newsletter/subscribed.html', {
28 'page_title': _(u'Subscribed'),
32 def check_subscription(subscription, hashcode):
33 if hashcode != subscription.hashcode():
37 def confirm_subscription(request, subscription_id, hashcode):
38 subscription = get_object_or_404(Subscription, id=subscription_id)
39 check_subscription(subscription, hashcode)
40 subscription.active = True
42 return render(request, 'newsletter/confirm_subscription.html', {
43 'page_title': _(u'Subscription confirmed')
47 def unsubscribe_form(request):
49 form = UnsubscribeForm(request.POST)
52 return HttpResponseRedirect(reverse('unsubscribed'))
54 form = UnsubscribeForm()
55 return render(request, 'newsletter/unsubscribe_form.html', {
56 'page_title': _(u'Unsubscribe'),
61 def unsubscribed(request):
62 return render(request, 'newsletter/unsubscribed.html', {
63 'page_title': _(u'Unsubscribed'),