view mysite/band/admin_views.py @ 20:7aa63299adf6

Adding a work around for IE path problem in the .css file, as per http://groups.google.com/group/fancybox/browse_frm/thread/8530478044b9f586
author Brian Neal <bgneal@gmail.com>
date Wed, 08 Sep 2010 23:15:57 +0000
parents 3e22a6fde2d2
children 25e00d1b99bf
line wrap: on
line source
#######################################################################
#
# PyBand Copyright (C) 2008 by Brian Neal
#
#######################################################################
from django import forms
from django.core.urlresolvers import reverse
from django.core.mail import EmailMessage
from django.template import RequestContext
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.contrib.admin.views.decorators import staff_member_required

from mysite.band.models import SiteConfig
from mysite.band.models import Fan

#######################################################################

unsubscribeText = '''

----
You are receiving this message because you are subscribed to our mailing list.
If you would like to unsubscribe please visit %s.
'''

#######################################################################

class EmailForm(forms.Form):
   subject = forms.CharField(max_length = 255, required = True, label = 'Subject:',
         widget = forms.TextInput(attrs = {'class' : 'vTextField required', 'size' : '60'}))
   message = forms.CharField(label = 'Message:',
         widget = forms.Textarea(attrs = {'class' : 'vLargeTextField required'}))

#######################################################################

def email_sent(request):
   return render_to_response('admin/band/email_sent.html',
         {},
         context_instance = RequestContext(request))

#######################################################################

def email(request):

   config = SiteConfig.objects.get(pk = 1)
   bandTag = '[%s] ' % (config.band_name, )

   if request.method == 'POST':
      form = EmailForm(request.POST)
      if form.is_valid():
         subject = form.cleaned_data['subject']
         message = form.cleaned_data['message']

         unsubscribeUrl = config.url
         if unsubscribeUrl[-1] != '/':
            unsubscribeUrl += '/'
         unsubscribeUrl += 'mail'

         footer = unsubscribeText % (unsubscribeUrl, )
         message += footer
         
         fans = Fan.objects.all()
         bcc = [fan.email for fan in fans]

         email = EmailMessage(subject, message, config.contact_email,
               [config.contact_email], bcc)
         email.send()
         return HttpResponseRedirect(reverse(email_sent))

   else:
      form = EmailForm(initial = { 'subject' : bandTag })

   return render_to_response('admin/band/email.html',
         { 'form' : form },
         context_instance = RequestContext(request))

email = staff_member_required(email)