newsletter stub
authorJan Szejko <jan.szejko@gmail.com>
Mon, 18 Jul 2016 14:15:32 +0000 (16:15 +0200)
committerJan Szejko <janek37@gmail.com>
Wed, 14 Sep 2016 10:47:47 +0000 (12:47 +0200)
13 files changed:
src/newsletter/__init__.py [new file with mode: 0644]
src/newsletter/admin.py [new file with mode: 0644]
src/newsletter/forms.py [new file with mode: 0644]
src/newsletter/locale/pl/LC_MESSAGES/django.po [new file with mode: 0644]
src/newsletter/migrations/0001_initial.py [new file with mode: 0644]
src/newsletter/migrations/__init__.py [new file with mode: 0644]
src/newsletter/models.py [new file with mode: 0644]
src/newsletter/templates/newsletter/unsubscribe.html [new file with mode: 0644]
src/newsletter/tests.py [new file with mode: 0644]
src/newsletter/urls.py [new file with mode: 0644]
src/newsletter/views.py [new file with mode: 0644]
src/wolnelektury/settings/__init__.py
src/wolnelektury/urls.py

diff --git a/src/newsletter/__init__.py b/src/newsletter/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/newsletter/admin.py b/src/newsletter/admin.py
new file mode 100644 (file)
index 0000000..8c38f3f
--- /dev/null
@@ -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 (file)
index 0000000..f8927e5
--- /dev/null
@@ -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 (file)
index 0000000..550b089
--- /dev/null
@@ -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 <EMAIL@ADDRESS>, 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 <jan.szejko@nowoczesnapolska.org.pl>\n"
+"Language-Team: LANGUAGE <LL@li.org>\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 (file)
index 0000000..6897278
--- /dev/null
@@ -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 (file)
index 0000000..e69de29
diff --git a/src/newsletter/models.py b/src/newsletter/models.py
new file mode 100644 (file)
index 0000000..481cb85
--- /dev/null
@@ -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 (file)
index 0000000..0661821
--- /dev/null
@@ -0,0 +1,6 @@
+{% extends "base/base.html" %}
+{% load i18n %}
+
+{% block body %}
+  <h1>{{ page_title }}</h1>
+{% endblock %}
\ No newline at end of file
diff --git a/src/newsletter/tests.py b/src/newsletter/tests.py
new file mode 100644 (file)
index 0000000..7ce503c
--- /dev/null
@@ -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 (file)
index 0000000..566f777
--- /dev/null
@@ -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 (file)
index 0000000..847530e
--- /dev/null
@@ -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
index 7c1dd29..13c7466 100644 (file)
@@ -57,7 +57,8 @@ INSTALLED_APPS_OUR = [
     'funding',
     'polls',
     'libraries',
-    ]
+    'newsletter',
+]
 
 GETPAID_BACKENDS = (
     'getpaid.backends.payu',
index f5dddaf..71bf1b5 100644 (file)
@@ -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<path>.*)$' % settings.MEDIA_URL[1:], 'django.views.static.serve',
+    url(r'^%s(?P<path>.*)$' % settings.MEDIA_URL[1:], django.views.static.serve,
         {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
-    url(r'^%s(?P<path>.*)$' % settings.STATIC_URL[1:], 'django.views.static.serve',
+    url(r'^%s(?P<path>.*)$' % 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)),
-)
+]