Mercurial > public > madeira
view mysite/band/admin_views.py @ 33:7d8015de651a
Removed old reference to /media in the admin/base_site.html template for the favicon.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 02 Nov 2011 01:30:46 +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)