0133e73ac3113f35876b70d7258a72eec4033585
[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     def get_urls(self):
12         urls = super(SubscriptionAdmin, self).get_urls()
13         my_urls = [
14             url(r'^extract/$', self.extract_subscribers, name='extract_subscribers'),
15         ]
16         return my_urls + urls
17
18     @never_cache
19     def extract_subscribers(self, request):
20         active_subscriptions = Subscription.objects.filter(active=True)
21         return HttpResponse('\n'.join(active_subscriptions.values_list('email', flat=True)),
22                             content_type='text/plain')
23
24
25 admin.site.register(Subscription, SubscriptionAdmin)