annotate email_list/admin.py @ 151:762e46d0bb4a

urlquote photologue filenames when building URLs.
author Brian Neal <bgneal@gmail.com>
date Wed, 30 Jul 2014 20:07:21 -0500
parents e2868ad47a1e
children 312f198e8958
rev   line source
bgneal@51 1 """
bgneal@51 2 Automatic admin definitions for the email_list application.
bgneal@51 3
bgneal@51 4 """
bgneal@51 5 from django.contrib import admin
bgneal@66 6 from django.conf.urls import patterns, url
bgneal@53 7 from django.shortcuts import render, redirect
bgneal@51 8
bgneal@51 9 from email_list.models import Subscriber
bgneal@53 10 from email_list.forms import AdminEmailForm
bgneal@51 11
bgneal@51 12
bgneal@51 13 class SubscriberAdmin(admin.ModelAdmin):
bgneal@53 14 list_display = ['__unicode__', 'location', 'status']
bgneal@53 15 list_filter = ['status']
bgneal@53 16 search_fields = ['name', 'email']
bgneal@53 17
bgneal@53 18 def get_urls(self):
bgneal@53 19 urls = super(SubscriberAdmin, self).get_urls()
bgneal@53 20 my_urls = patterns('',
bgneal@53 21 url(r'^send_mail/$',
bgneal@53 22 self.admin_site.admin_view(self.send_mail),
bgneal@53 23 name='email_list-admin_mail'),
bgneal@53 24 )
bgneal@53 25 return my_urls + urls
bgneal@53 26
bgneal@53 27 def send_mail(self, request):
bgneal@53 28 if request.method == 'POST':
bgneal@53 29 form = AdminEmailForm(request.POST)
bgneal@53 30 if form.is_valid():
bgneal@53 31 n = form.save()
bgneal@53 32 msg = '%d mailing list emails sent' % n
bgneal@53 33 self.message_user(request, msg)
bgneal@53 34 return redirect('admin:index')
bgneal@53 35 else:
bgneal@53 36 form = AdminEmailForm()
bgneal@53 37
bgneal@53 38 return render(request, 'email_list/admin_mail.html', {'form': form})
bgneal@51 39
bgneal@51 40
bgneal@51 41 admin.site.register(Subscriber, SubscriberAdmin)