1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from django.urls import path
5 from django.contrib import admin
6 from django.http.response import HttpResponse
7 from django.views.decorators.cache import never_cache
8 from modeltranslation.admin import TranslationAdmin
9 from newsletter.models import Subscription, Newsletter
12 class SubscriptionAdmin(admin.ModelAdmin):
13 list_display = ('email', 'active')
14 list_filter = ('active',)
17 urls = super(SubscriptionAdmin, self).get_urls()
19 path('extract/', self.extract_subscribers, name='extract_subscribers'),
24 def extract_subscribers(self, request):
25 active_subscriptions = Subscription.objects.filter(active=True)
26 return HttpResponse('\n'.join(active_subscriptions.values_list('email', flat=True)),
27 content_type='text/plain')
30 admin.site.register(Subscription, SubscriptionAdmin)
33 admin.site.register(Newsletter, TranslationAdmin)