diff email_list/admin.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/admin.py@9b9daefba97a
children 312f198e8958
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/email_list/admin.py	Sat Apr 14 16:40:29 2012 -0500
@@ -0,0 +1,41 @@
+"""
+Automatic admin definitions for the email_list application.
+
+"""
+from django.contrib import admin
+from django.conf.urls import patterns, url
+from django.shortcuts import render, redirect
+
+from email_list.models import Subscriber
+from email_list.forms import AdminEmailForm
+
+
+class SubscriberAdmin(admin.ModelAdmin):
+    list_display = ['__unicode__', 'location', 'status']
+    list_filter = ['status']
+    search_fields = ['name', 'email']
+
+    def get_urls(self):
+        urls = super(SubscriberAdmin, self).get_urls()
+        my_urls = patterns('',
+            url(r'^send_mail/$',
+                self.admin_site.admin_view(self.send_mail),
+                name='email_list-admin_mail'),
+        )
+        return my_urls + urls
+
+    def send_mail(self, request):
+        if request.method == 'POST':
+            form = AdminEmailForm(request.POST)
+            if form.is_valid():
+                n = form.save()
+                msg = '%d mailing list emails sent' % n
+                self.message_user(request, msg)
+                return redirect('admin:index')
+        else:
+            form = AdminEmailForm()
+
+        return render(request, 'email_list/admin_mail.html', {'form': form})
+
+
+admin.site.register(Subscriber, SubscriberAdmin)