comparison mysite/band/admin_views.py @ 1:0dcfcdf50c62

Initial import of Madeira project from the private repository.
author Brian Neal <bgneal@gmail.com>
date Mon, 06 Apr 2009 03:10:59 +0000
parents
children 3e22a6fde2d2
comparison
equal deleted inserted replaced
0:df0370bfe3f0 1:0dcfcdf50c62
1 #######################################################################
2 #
3 # PyBand Copyright (C) 2008 by Brian Neal
4 #
5 #######################################################################
6 from django import forms
7 from django.core.urlresolvers import reverse
8 from django.core.mail import EmailMessage
9 from django.template import RequestContext
10 from django.http import HttpResponseRedirect
11 from django.shortcuts import render_to_response
12 from django.contrib.admin.views.decorators import staff_member_required
13
14 from mysite.band.models import SiteConfig
15 from mysite.band.models import Fan
16
17 #######################################################################
18
19 unsubscribeText = '''
20
21 ----
22 You are receiving this message because you are subscribed to our mailing list.
23 If you would like to unsubscribe please visit %s.
24 '''
25
26 #######################################################################
27
28 class EmailForm(forms.Form):
29 subject = forms.CharField(max_length = 255, required = True, label = 'Subject:',
30 widget = forms.TextInput(attrs = {'class' : 'vTextField required', 'size' : '60'}))
31 message = forms.CharField(label = 'Message:',
32 widget = forms.Textarea(attrs = {'class' : 'vLargeTextField required'}))
33
34 #######################################################################
35
36 def email_sent(request):
37 return render_to_response('admin/band/email_sent.html',
38 {},
39 context_instance = RequestContext(request))
40
41 #######################################################################
42
43 def email(request):
44
45 config = SiteConfig.objects.get(pk = 1)
46 bandTag = '[%s] ' % (config.band_name, )
47
48 if request.method == 'POST':
49 form = EmailForm(request.POST)
50 if form.is_valid():
51 subject = form.cleaned_data['subject']
52 message = form.cleaned_data['message']
53
54 unsubscribeUrl = config.url
55 if unsubscribeUrl[-1] != '/':
56 unsubscribeUrl += '/'
57 unsubscribeUrl += 'contact'
58
59 footer = unsubscribeText % (unsubscribeUrl, )
60 message += footer
61
62 fans = Fan.objects.all()
63 bcc = [fan.email for fan in fans]
64
65 email = EmailMessage(subject, message, config.contact_email,
66 [config.contact_email], bcc)
67 email.send()
68 return HttpResponseRedirect(reverse(email_sent))
69
70 else:
71 form = EmailForm(initial = { 'subject' : bandTag })
72
73 return render_to_response('admin/band/email.html',
74 { 'form' : form },
75 context_instance = RequestContext(request))
76
77 email = staff_member_required(email)