From: Jan Szejko Date: Fri, 29 Jul 2016 15:25:33 +0000 (+0200) Subject: admin support for newsletter X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/20785520a46a699410126303b3969abf214a68c8?hp=65d6c08f9187d565fe4b9bfa95ca32f7509429b1 admin support for newsletter --- diff --git a/src/newsletter/admin.py b/src/newsletter/admin.py index 8c38f3f3d..bcb789761 100644 --- a/src/newsletter/admin.py +++ b/src/newsletter/admin.py @@ -1,3 +1,21 @@ +# -*- coding: utf-8 -*- +from django.conf.urls import url from django.contrib import admin +from django.http.response import HttpResponse -# Register your models here. +from newsletter.models import Subscription + + +class SubscriptionAdmin(admin.ModelAdmin): + def get_urls(self): + urls = super(SubscriptionAdmin, self).get_urls() + my_urls = [ + url(r'^extract/$', self.extract_subscribers, name='extract_subscribers'), + ] + return my_urls + urls + + def extract_subscribers(self, request): + return HttpResponse(',\n'.join(Subscription.objects.values_list('email', flat=True)), content_type='text/plain') + + +admin.site.register(Subscription, SubscriptionAdmin) diff --git a/src/newsletter/models.py b/src/newsletter/models.py index 481cb85a3..6d100a380 100644 --- a/src/newsletter/models.py +++ b/src/newsletter/models.py @@ -4,7 +4,14 @@ from django.utils.translation import ugettext_lazy as _ class Subscription(Model): - email = EmailField(verbose_name=_('email address')) - active = BooleanField(default=True) + email = EmailField(verbose_name=_('email address'), unique=True) + active = BooleanField(default=True, verbose_name=_(u'active')) created_at = DateTimeField(auto_now_add=True) last_modified = DateTimeField(auto_now=True) + + class Meta: + verbose_name = _('subscription') + verbose_name_plural = _('subscriptions') + + def __unicode__(self): + return self.email \ No newline at end of file diff --git a/src/newsletter/templates/admin/newsletter/subscription/change_list.html b/src/newsletter/templates/admin/newsletter/subscription/change_list.html new file mode 100644 index 000000000..4a301df30 --- /dev/null +++ b/src/newsletter/templates/admin/newsletter/subscription/change_list.html @@ -0,0 +1,14 @@ +{% extends "admin/change_list.html" %} +{% load i18n %} +{% load admin_urls %} + + +{% block object-tools-items %} +
  • + + {% trans 'Extract' %} + +
  • + {{block.super}} +{% endblock %} +