From de08100bad0d82b2823453ecccaa66fd7521cd41 Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Mon, 18 Jul 2016 16:15:32 +0200 Subject: [PATCH] newsletter stub --- src/newsletter/__init__.py | 0 src/newsletter/admin.py | 3 + src/newsletter/forms.py | 24 ++++++++ .../locale/pl/LC_MESSAGES/django.po | 31 ++++++++++ src/newsletter/migrations/0001_initial.py | 23 ++++++++ src/newsletter/migrations/__init__.py | 0 src/newsletter/models.py | 10 ++++ .../templates/newsletter/unsubscribe.html | 6 ++ src/newsletter/tests.py | 3 + src/newsletter/urls.py | 7 +++ src/newsletter/views.py | 9 +++ src/wolnelektury/settings/__init__.py | 3 +- src/wolnelektury/urls.py | 57 +++++++++---------- 13 files changed, 146 insertions(+), 30 deletions(-) create mode 100644 src/newsletter/__init__.py create mode 100644 src/newsletter/admin.py create mode 100644 src/newsletter/forms.py create mode 100644 src/newsletter/locale/pl/LC_MESSAGES/django.po create mode 100644 src/newsletter/migrations/0001_initial.py create mode 100644 src/newsletter/migrations/__init__.py create mode 100644 src/newsletter/models.py create mode 100644 src/newsletter/templates/newsletter/unsubscribe.html create mode 100644 src/newsletter/tests.py create mode 100644 src/newsletter/urls.py create mode 100644 src/newsletter/views.py diff --git a/src/newsletter/__init__.py b/src/newsletter/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/newsletter/admin.py b/src/newsletter/admin.py new file mode 100644 index 000000000..8c38f3f3d --- /dev/null +++ b/src/newsletter/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/src/newsletter/forms.py b/src/newsletter/forms.py new file mode 100644 index 000000000..f8927e5b8 --- /dev/null +++ b/src/newsletter/forms.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +from django.forms import Form, BooleanField +from django.utils.translation import ugettext_lazy as _ + +from newsletter.models import Subscription + + +class NewsletterForm(Form): + email_field = 'email' + agree_newsletter = BooleanField(required=False, label=_(u'I want to receive Wolne Lektury\'s newsletter.')) + + def save(self): + try: + # multiple inheritance mode + super(NewsletterForm, self).save() + except AttributeError: + pass + email = self.cleaned_data[self.email_field] + subscription, created = Subscription.objects.get_or_create(email=email) + if not created and not subscription.active: + subscription.active = True + subscription.save() + # Send some test email? diff --git a/src/newsletter/locale/pl/LC_MESSAGES/django.po b/src/newsletter/locale/pl/LC_MESSAGES/django.po new file mode 100644 index 000000000..550b08999 --- /dev/null +++ b/src/newsletter/locale/pl/LC_MESSAGES/django.po @@ -0,0 +1,31 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-07-18 15:48+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: Jan Szejko \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 " +"|| n%100>=20) ? 1 : 2);\n" + +#: forms.py:11 +msgid "I want to receive Wolne Lektury's newsletter." +msgstr "Chcę otrzymywać newsletter Wolnych Lektur" + +#: models.py:7 +msgid "email address" +msgstr "adres email" + +#: views.py:8 +msgid "Unsubscribe" +msgstr "Usuń subskrypcję" diff --git a/src/newsletter/migrations/0001_initial.py b/src/newsletter/migrations/0001_initial.py new file mode 100644 index 000000000..6897278b2 --- /dev/null +++ b/src/newsletter/migrations/0001_initial.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Subscription', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('email', models.EmailField(max_length=254, verbose_name='email address')), + ('active', models.BooleanField(default=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('last_modified', models.DateTimeField(auto_now=True)), + ], + ), + ] diff --git a/src/newsletter/migrations/__init__.py b/src/newsletter/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/newsletter/models.py b/src/newsletter/models.py new file mode 100644 index 000000000..481cb85a3 --- /dev/null +++ b/src/newsletter/models.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +from django.db.models import Model, EmailField, DateTimeField, BooleanField +from django.utils.translation import ugettext_lazy as _ + + +class Subscription(Model): + email = EmailField(verbose_name=_('email address')) + active = BooleanField(default=True) + created_at = DateTimeField(auto_now_add=True) + last_modified = DateTimeField(auto_now=True) diff --git a/src/newsletter/templates/newsletter/unsubscribe.html b/src/newsletter/templates/newsletter/unsubscribe.html new file mode 100644 index 000000000..06618212e --- /dev/null +++ b/src/newsletter/templates/newsletter/unsubscribe.html @@ -0,0 +1,6 @@ +{% extends "base/base.html" %} +{% load i18n %} + +{% block body %} +

{{ page_title }}

+{% endblock %} \ No newline at end of file diff --git a/src/newsletter/tests.py b/src/newsletter/tests.py new file mode 100644 index 000000000..7ce503c2d --- /dev/null +++ b/src/newsletter/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/src/newsletter/urls.py b/src/newsletter/urls.py new file mode 100644 index 000000000..566f777f4 --- /dev/null +++ b/src/newsletter/urls.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +from django.conf.urls import url +from . import views + +urlpatterns = [ + url(r'^wypisz-sie/$', views.unsubscribe, name='unsubscribe'), +] diff --git a/src/newsletter/views.py b/src/newsletter/views.py new file mode 100644 index 000000000..847530e16 --- /dev/null +++ b/src/newsletter/views.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +from django.shortcuts import render +from django.utils.translation import ugettext_lazy as _ + + +def unsubscribe(request): + return render(request, 'newsletter/unsubscribe.html', { + 'page_title': _(u'Unsubscribe'), + }) \ No newline at end of file diff --git a/src/wolnelektury/settings/__init__.py b/src/wolnelektury/settings/__init__.py index 7c1dd2983..13c7466cf 100644 --- a/src/wolnelektury/settings/__init__.py +++ b/src/wolnelektury/settings/__init__.py @@ -57,7 +57,8 @@ INSTALLED_APPS_OUR = [ 'funding', 'polls', 'libraries', - ] + 'newsletter', +] GETPAID_BACKENDS = ( 'getpaid.backends.payu', diff --git a/src/wolnelektury/urls.py b/src/wolnelektury/urls.py index f5dddafd3..71bf1b54a 100644 --- a/src/wolnelektury/urls.py +++ b/src/wolnelektury/urls.py @@ -2,36 +2,35 @@ # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # -from django.conf.urls import include, patterns, url +from django.conf.urls import include, url from django.conf import settings from django.contrib import admin from django.views.generic import RedirectView -import wolnelektury.views +import django.views.static +import catalogue.views +import picture.views +from . import views -urlpatterns = patterns( - 'wolnelektury.views', - url(r'^$', 'main_page', name='main_page'), - url(r'^planowane/$', 'publish_plan', name='publish_plan'), - url(r'^widget\.html$', 'widget', name='widget'), +urlpatterns = [ + url(r'^$', views.main_page, name='main_page'), + url(r'^planowane/$', views.publish_plan, name='publish_plan'), + url(r'^widget\.html$', views.widget, name='widget'), - url(r'^zegar/$', 'clock', name='clock'), + url(r'^zegar/$', views.clock, name='clock'), # Authentication - url(r'^uzytkownik/$', 'user_settings', name='user_settings'), - url(r'^uzytkownik/login/$', wolnelektury.views.LoginFormView(), name='login'), - url(r'^uzytkownik/signup/$', wolnelektury.views.RegisterFormView(), name='register'), - url(r'^uzytkownik/logout/$', 'logout_then_redirect', name='logout'), - url(r'^uzytkownik/zaloguj-utworz/$', wolnelektury.views.LoginRegisterFormView(), name='login_register'), + url(r'^uzytkownik/$', views.user_settings, name='user_settings'), + url(r'^uzytkownik/login/$', views.LoginFormView(), name='login'), + url(r'^uzytkownik/signup/$', views.RegisterFormView(), name='register'), + url(r'^uzytkownik/logout/$', views.logout_then_redirect, name='logout'), + url(r'^uzytkownik/zaloguj-utworz/$', views.LoginRegisterFormView(), name='login_register'), # Includes. - url(r'^latests_blog_posts.html$', - wolnelektury.views.latest_blog_posts, - name='latest_blog_posts'), -) + url(r'^latests_blog_posts.html$', views.latest_blog_posts, name='latest_blog_posts'), +] -urlpatterns += patterns( - '', +urlpatterns += [ url(r'^katalog/', include('catalogue.urls')), url(r'^opds/', include('opds.urls')), url(r'^sugestia/', include('suggest.urls')), @@ -47,30 +46,30 @@ urlpatterns += patterns( url(r'^biblioteki/', include('libraries.urls')), url(r'^chunks/', include('chunks.urls')), url(r'^sponsors/', include('sponsors.urls')), + url(r'^newsletter/', include('newsletter.urls')), # Admin panel - url(r'^admin/catalogue/book/import$', 'catalogue.views.import_book', name='import_book'), - url(r'^admin/catalogue/picture/import$', 'picture.views.import_picture', name='import_picture'), + url(r'^admin/catalogue/book/import$', catalogue.views.import_book, name='import_book'), + url(r'^admin/catalogue/picture/import$', picture.views.import_picture, name='import_picture'), url(r'^admin/doc/', include('django.contrib.admindocs.urls')), url(r'^admin/', include(admin.site.urls)), # API - (r'^api/', include('api.urls')), + url(r'^api/', include('api.urls')), # OAIPMH - (r'^oaipmh/', include('oai.urls')), + url(r'^oaipmh/', include('oai.urls')), url(r'^szukaj/', include('search.urls')), # Static files - url(r'^%s(?P.*)$' % settings.MEDIA_URL[1:], 'django.views.static.serve', + url(r'^%s(?P.*)$' % settings.MEDIA_URL[1:], django.views.static.serve, {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}), - url(r'^%s(?P.*)$' % settings.STATIC_URL[1:], 'django.views.static.serve', + url(r'^%s(?P.*)$' % settings.STATIC_URL[1:], django.views.static.serve, {'document_root': settings.STATIC_ROOT, 'show_indexes': True}), url(r'^i18n/', include('django.conf.urls.i18n')), -) +] -urlpatterns += patterns( - '', +urlpatterns += [ # old static pages - redirected url(r'^1procent/$', RedirectView.as_view( url='http://nowoczesnapolska.org.pl/wesprzyj_nas/', permanent=True)), @@ -84,4 +83,4 @@ urlpatterns += patterns( url='/info/widget/', permanent=True)), url(r'^wolontariat/$', RedirectView.as_view( url='/info/wlacz-sie-w-prace/', permanent=False)), -) +] -- 2.20.1