Mercurial > public > madeira
comparison email_list/views.py @ 71:e2868ad47a1e
For Django 1.4, using the new manage.py.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 14 Apr 2012 16:40:29 -0500 |
parents | madeira/email_list/views.py@7f9e76e7eb4d |
children |
comparison
equal
deleted
inserted
replaced
70:f26cdda0ad8b | 71:e2868ad47a1e |
---|---|
1 """ | |
2 Views for the email_list application. | |
3 | |
4 """ | |
5 import logging | |
6 | |
7 from django.http import HttpResponseServerError | |
8 from django.shortcuts import render, redirect, get_object_or_404 | |
9 | |
10 from email_list.forms import SubscriberForm | |
11 from email_list.models import Subscriber | |
12 | |
13 | |
14 logger = logging.getLogger(__name__) | |
15 | |
16 | |
17 def mailing_list(request): | |
18 """ | |
19 The main view for handling email list actions (subscribe or unsubscribe). | |
20 | |
21 """ | |
22 if request.method == 'POST': | |
23 form = SubscriberForm(request.POST) | |
24 if form.is_valid(): | |
25 form.process() | |
26 | |
27 if form.is_subscribe(): | |
28 return redirect('email_list-request_subscribe') | |
29 else: | |
30 return redirect('email_list-request_unsubscribe') | |
31 | |
32 else: | |
33 form = SubscriberForm() | |
34 | |
35 return render(request, 'email_list/subscribe_form.html', {'form': form}) | |
36 | |
37 | |
38 def confirm(request, key): | |
39 """ | |
40 This view handles the confirmation of a subscribe or unsubscribe action. | |
41 | |
42 """ | |
43 subscriber = get_object_or_404(Subscriber, key=key) | |
44 | |
45 if subscriber.is_pending(): | |
46 subscriber.set_active() | |
47 subscriber.save() | |
48 return redirect('email_list-subscribed') | |
49 elif subscriber.is_leaving(): | |
50 subscriber.delete() | |
51 return redirect('email_list-unsubscribed') | |
52 | |
53 # This should not happen | |
54 logger.error("Trying to confirm subscriber %d, but status is %s", | |
55 subscriber.pk, subscriber.status) | |
56 return HttpResponseServerError() |