better login/register page (new default login)
[wolnelektury.git] / src / newsletter / admin.py
1 # -*- coding: utf-8 -*-
2 from django.conf.urls import url
3 from django.contrib import admin
4 from django.http.response import HttpResponse
5 from django.views.decorators.cache import never_cache
6
7 from newsletter.models import Subscription
8
9
10 class SubscriptionAdmin(admin.ModelAdmin):
11     list_display = ('email', 'active')
12     list_filter = ('active',)
13
14     def get_urls(self):
15         urls = super(SubscriptionAdmin, self).get_urls()
16         my_urls = [
17             url(r'^extract/$', self.extract_subscribers, name='extract_subscribers'),
18         ]
19         return my_urls + urls
20
21     @never_cache
22     def extract_subscribers(self, request):
23         active_subscriptions = Subscription.objects.filter(active=True)
24         return HttpResponse('\n'.join(active_subscriptions.values_list('email', flat=True)),
25                             content_type='text/plain')
26
27
28 admin.site.register(Subscription, SubscriptionAdmin)