From 33209aed7c3e858d95576bdcfefa17c3f5d7597b Mon Sep 17 00:00:00 2001 From: luxagraf Date: Wed, 5 Feb 2020 16:18:53 -0500 Subject: migrated newsletter templates and updated mailing model --- app/lttr/admin.py | 31 ++++++++++++++++- app/lttr/migrations/0005_auto_20200205_1606.py | 31 +++++++++++++++++ app/lttr/models.py | 20 +++++++++-- app/lttr/templates/lttr/confirm_activate.html | 17 ++++++++++ app/lttr/templates/lttr/message/subscribe.html | 24 +++++++++++++ app/lttr/templates/lttr/message/subscribe.txt | 9 +++++ .../templates/lttr/message/subscribe_subject.txt | 1 + app/lttr/templates/lttr/message/unsubscribe.html | 19 +++++++++++ app/lttr/templates/lttr/message/unsubscribe.txt | 9 +++++ .../templates/lttr/message/unsubscribe_subject.txt | 1 + app/lttr/templates/lttr/subscribed.html | 17 ++++++++++ app/lttr/templates/lttr/subscriber_form.html | 39 ++++++++++++++++++++++ app/lttr/views.py | 11 ++++++ 13 files changed, 225 insertions(+), 4 deletions(-) create mode 100644 app/lttr/migrations/0005_auto_20200205_1606.py create mode 100644 app/lttr/templates/lttr/confirm_activate.html create mode 100644 app/lttr/templates/lttr/message/subscribe.html create mode 100644 app/lttr/templates/lttr/message/subscribe.txt create mode 100644 app/lttr/templates/lttr/message/subscribe_subject.txt create mode 100644 app/lttr/templates/lttr/message/unsubscribe.html create mode 100644 app/lttr/templates/lttr/message/unsubscribe.txt create mode 100644 app/lttr/templates/lttr/message/unsubscribe_subject.txt create mode 100644 app/lttr/templates/lttr/subscribed.html create mode 100644 app/lttr/templates/lttr/subscriber_form.html (limited to 'app') diff --git a/app/lttr/admin.py b/app/lttr/admin.py index 1b919d6..4ca30ce 100644 --- a/app/lttr/admin.py +++ b/app/lttr/admin.py @@ -1,7 +1,8 @@ from django.contrib import admin -from .models import NewsletterMailing, Subscriber +from utils.widgets import AdminImageWidget, LGEntryForm +from .models import NewsletterMailing, Subscriber @admin.register(Subscriber) class SubscriberAdmin(admin.ModelAdmin): @@ -11,3 +12,31 @@ class SubscriberAdmin(admin.ModelAdmin): class Media: js = ('next-prev-links.js',) + + +@admin.register(NewsletterMailing) +class NewsletterMailingAdmin(admin.ModelAdmin): + form = LGEntryForm + list_display = ('title', 'pub_date', 'status') + fieldsets = ( + ('Entry', { + 'fields': ( + 'title', + 'body_markdown', + ('pub_date', 'status'), + 'slug', + 'featured_image', + ), + 'classes': ( + 'show', + 'extrapretty', + 'wide' + ) + } + ), + ) + class Media: + js = ('image-loader.js', 'next-prev-links.js') + css = { + "all": ("my_styles.css",) + } diff --git a/app/lttr/migrations/0005_auto_20200205_1606.py b/app/lttr/migrations/0005_auto_20200205_1606.py new file mode 100644 index 0000000..0be644e --- /dev/null +++ b/app/lttr/migrations/0005_auto_20200205_1606.py @@ -0,0 +1,31 @@ +# Generated by Django 2.1.2 on 2020-02-05 16:06 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('photos', '0019_auto_20190704_0903'), + ('lttr', '0004_auto_20190212_1529'), + ] + + operations = [ + migrations.AddField( + model_name='newslettermailing', + name='body_html', + field=models.TextField(blank=True), + ), + migrations.AddField( + model_name='newslettermailing', + name='body_markdown', + field=models.TextField(default='tk'), + preserve_default=False, + ), + migrations.AddField( + model_name='newslettermailing', + name='featured_image', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='photos.LuxImage'), + ), + ] diff --git a/app/lttr/models.py b/app/lttr/models.py index ec5e897..4ab6030 100644 --- a/app/lttr/models.py +++ b/app/lttr/models.py @@ -12,6 +12,7 @@ from django.utils.crypto import get_random_string from taggit.managers import TaggableManager from taxonomy.models import TaggedItems +from photos.models import LuxImage, LuxImageSize # Possible actions that user can perform @@ -101,7 +102,10 @@ class NewsletterMailing(models.Model): """ A model for Newletter Mailings, the things actually sent out """ title = models.CharField(max_length=250) slug = models.SlugField(unique_for_date='pub_date', blank=True) + body_html = models.TextField(blank=True) + body_markdown = models.TextField() pub_date = models.DateTimeField() + featured_image = models.ForeignKey(LuxImage, on_delete=models.CASCADE, null=True, blank=True) tags = TaggableManager(through=TaggedItems, blank=True, help_text='Topics Covered') PUB_STATUS = ( (0, 'Not Published'), @@ -120,8 +124,20 @@ class NewsletterMailing(models.Model): return reverse("newsletter:mailing-detail", kwargs={"slug": self.slug}) def save(self, *args, **kwargs): - if not self.id: + created = self.pk is None + if not created: + md = render_images(self.body_markdown) + self.body_html = markdown_to_html(md) self.date_created = timezone.now() + if created and not self.featured_image: + self.featured_image = LuxImage.objects.latest() + old = type(self).objects.get(pk=self.pk) if self.pk else None + if old and old.featured_image != self.featured_image: # Field has changed + s = LuxImageSize.objects.get(name="featured_jrnl") + ss = LuxImageSize.objects.get(name="picwide-med") + self.featured_image.sizes.add(s) + self.featured_image.sizes.add(ss) + self.featured_image.save() super(NewsletterMailing, self).save() @@ -298,8 +314,6 @@ class Subscriber(models.Model): def get_address(name, email): - # Converting name to ascii for compatibility with django < 1.9. - # Remove this when django 1.8 is no longer supported. if name: return u'%s <%s>' % (name, email) else: diff --git a/app/lttr/templates/lttr/confirm_activate.html b/app/lttr/templates/lttr/confirm_activate.html new file mode 100644 index 0000000..d67ee1b --- /dev/null +++ b/app/lttr/templates/lttr/confirm_activate.html @@ -0,0 +1,17 @@ +{% extends 'base.html' %} +{% load typogrify_tags %} + +{% block pagetitle %}Luxagraf | Friends of a Long Year {% endblock %} +{% block metadescription %}An infrequesnt mailing list about travel, photography, tools, walking, the natural world and other ephemera.{% endblock %} + +{% block primary %} +
+
+

You're confirmed, thanks for joining.

+

If you'd like you can visit the archives of past mailings.

+
+
+{%endblock%} diff --git a/app/lttr/templates/lttr/message/subscribe.html b/app/lttr/templates/lttr/message/subscribe.html new file mode 100644 index 0000000..3ed34db --- /dev/null +++ b/app/lttr/templates/lttr/message/subscribe.html @@ -0,0 +1,24 @@ +{% load i18n %} + + + + + {% blocktrans with title=newsletter.title %}Subscription to {{ title }}{% endblocktrans %} + + + +{% blocktrans with name=subscription.name title=newsletter.title domain=site.domain url=subscription.subscribe_activate_url %} + +

Hola-

+ +

Someone, hopefully you, asked to subscribe to {{ title }}, a luxagraf.net letter.

+ +

To confirm your subscription, please follow this activation link: +

+ +https://{{ domain }}{{ url }} +{% endblocktrans %} +

cheers
+Scott

+ + diff --git a/app/lttr/templates/lttr/message/subscribe.txt b/app/lttr/templates/lttr/message/subscribe.txt new file mode 100644 index 0000000..2af5378 --- /dev/null +++ b/app/lttr/templates/lttr/message/subscribe.txt @@ -0,0 +1,9 @@ +Hola- + +Someone, hopefully you, asked to subscribe to {{ newsletter.title }}, a luxagraf.net letter. + +If you would like to confirm your subscription, please follow this activation link: +https://{{ site.domain }}{{ subscription.subscribe_activate_url }} + +cheers +Scott diff --git a/app/lttr/templates/lttr/message/subscribe_subject.txt b/app/lttr/templates/lttr/message/subscribe_subject.txt new file mode 100644 index 0000000..f4660e0 --- /dev/null +++ b/app/lttr/templates/lttr/message/subscribe_subject.txt @@ -0,0 +1 @@ +Confirm Your Subscription to {{newsletter.title}} diff --git a/app/lttr/templates/lttr/message/unsubscribe.html b/app/lttr/templates/lttr/message/unsubscribe.html new file mode 100644 index 0000000..4b1a86b --- /dev/null +++ b/app/lttr/templates/lttr/message/unsubscribe.html @@ -0,0 +1,19 @@ +{% load i18n %} + + + + + {% blocktrans with title=newsletter.title %}Unsubscription from {{ title }}{% endblocktrans %} + + +{% blocktrans with name=subscription.name title=newsletter.title domain=site.domain url=subscription.unsubscribe_activate_url %}Dear {{ name }}, + +you, or someone in your name requested unsubscription from {{ title }}. + +If you would like to confirm your unsubscription, please follow this activation link: +http://{{ domain }}{{ url }} + +Kind regards,{% endblocktrans %} +{{ newsletter.sender }} + + diff --git a/app/lttr/templates/lttr/message/unsubscribe.txt b/app/lttr/templates/lttr/message/unsubscribe.txt new file mode 100644 index 0000000..ab31fa5 --- /dev/null +++ b/app/lttr/templates/lttr/message/unsubscribe.txt @@ -0,0 +1,9 @@ +{% load i18n %}{% blocktrans with name=subscription.name title=newsletter.title domain=site.domain url=subscription.unsubscribe_activate_url %}Dear {{ name }}, + +you, or someone in your name requested unsubscription from {{ title }}. + +If you would like to confirm your unsubscription, please follow this activation link: +http://{{ domain }}{{ url }} + +Kind regards,{% endblocktrans %} +{{ newsletter.sender }} diff --git a/app/lttr/templates/lttr/message/unsubscribe_subject.txt b/app/lttr/templates/lttr/message/unsubscribe_subject.txt new file mode 100644 index 0000000..49c68ef --- /dev/null +++ b/app/lttr/templates/lttr/message/unsubscribe_subject.txt @@ -0,0 +1 @@ +{% load i18n %}{{ newsletter.title }} - {% trans "Confirm unsubscription" %} diff --git a/app/lttr/templates/lttr/subscribed.html b/app/lttr/templates/lttr/subscribed.html new file mode 100644 index 0000000..18ad151 --- /dev/null +++ b/app/lttr/templates/lttr/subscribed.html @@ -0,0 +1,17 @@ +{% extends 'base.html' %} +{% load typogrify_tags %} + +{% block pagetitle %}Luxagraf | Friends of a Long Year {% endblock %} +{% block metadescription %}An infrequesnt mailing list about travel, photography, tools, walking, the natural world and other ephemera.{% endblock %} + +{% block primary %} +
+
+

Thanks for joining.

+

Check your email for a link to confirm your subscription

+
+
+{%endblock%} diff --git a/app/lttr/templates/lttr/subscriber_form.html b/app/lttr/templates/lttr/subscriber_form.html new file mode 100644 index 0000000..83e1e28 --- /dev/null +++ b/app/lttr/templates/lttr/subscriber_form.html @@ -0,0 +1,39 @@ +{% extends 'base.html' %} +{% load typogrify_tags %} + +{% block pagetitle %}Luxagraf | Friends of a Long Year {% endblock %} +{% block metadescription %}An infrequesnt mailing list about travel, photography, tools, walking, the natural world and other ephemera.{% endblock %} + +{% block primary %} +
+
+

Join the Friends of a Long Year.

+ + {% if field.errors %}{{field.errors}}{% endif %} + {%endfor%} +

Say what?

+

Friends of a Long Year is an infrequent mailing that will keep you up-to-date with luxagraf and offer some thoughts on topics like travel, photography, the natural world, tools, walking and other ephemera. It comes about twice a month, sometimes less, sometimes more. Unsubscribing is easy. It's all self-hosted, secure, and private.

+

The name comes from the great early 20th century explorer and desert rat, Mary Hunter Austin, whose collected essays, Lost Borders is dedicated to the "Friends of a Long Year". This somewhat inscrutable dedication grabbed me, and seemed like the perfect name for this mailing list.

+
+

Letters

+ +
+{%endblock%} diff --git a/app/lttr/views.py b/app/lttr/views.py index 0d3dbea..79b8e72 100644 --- a/app/lttr/views.py +++ b/app/lttr/views.py @@ -90,3 +90,14 @@ class ConfirmSubscriptionView(DetailView): if obj.subscribed is False: obj.update('subscribe') return obj + + +class UnsubscribeRequestView(DetailView): + model = Subscriber + template_name = "lttr/unsubscribe.html" + + def get_object(self): + obj = Subscriber.objects.get(newsletter__slug=self.kwargs['slug']) + if obj.subscribed is True: + obj.update('unsubscribe') + return obj -- cgit v1.2.3-70-g09d2