bgneal@51: """ bgneal@51: Automatic admin definitions for the email_list application. bgneal@51: bgneal@51: """ bgneal@51: from django.contrib import admin bgneal@66: from django.conf.urls import patterns, url bgneal@53: from django.shortcuts import render, redirect bgneal@51: bgneal@51: from email_list.models import Subscriber bgneal@53: from email_list.forms import AdminEmailForm bgneal@51: bgneal@51: bgneal@51: class SubscriberAdmin(admin.ModelAdmin): bgneal@53: list_display = ['__unicode__', 'location', 'status'] bgneal@53: list_filter = ['status'] bgneal@53: search_fields = ['name', 'email'] bgneal@53: bgneal@53: def get_urls(self): bgneal@53: urls = super(SubscriberAdmin, self).get_urls() bgneal@53: my_urls = patterns('', bgneal@53: url(r'^send_mail/$', bgneal@53: self.admin_site.admin_view(self.send_mail), bgneal@53: name='email_list-admin_mail'), bgneal@53: ) bgneal@53: return my_urls + urls bgneal@53: bgneal@53: def send_mail(self, request): bgneal@53: if request.method == 'POST': bgneal@53: form = AdminEmailForm(request.POST) bgneal@53: if form.is_valid(): bgneal@53: n = form.save() bgneal@53: msg = '%d mailing list emails sent' % n bgneal@53: self.message_user(request, msg) bgneal@53: return redirect('admin:index') bgneal@53: else: bgneal@53: form = AdminEmailForm() bgneal@53: bgneal@53: return render(request, 'email_list/admin_mail.html', {'form': form}) bgneal@51: bgneal@51: bgneal@51: admin.site.register(Subscriber, SubscriberAdmin)