From 5b2670859f67f9dc9a3d1dc51b033709c0bafd66 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 2 Mar 2025 22:25:40 +0100 Subject: [PATCH 1/2] use week title in email --- app/item/views.py | 13 +++++++++++++ app/listmonk/utils.py | 2 +- app/listmonk/views.py | 4 ++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/item/views.py b/app/item/views.py index 01fb87d..bc4254d 100644 --- a/app/item/views.py +++ b/app/item/views.py @@ -43,6 +43,19 @@ def format_week(week): extra = '' return '%s - %s%s' % (a, b, extra) +def format_subject(monday): + a = datetime.strptime(monday, '%Y-%m-%d') + b = (a + timedelta(days=6)) + fmt = '%b %d' + a = a.strftime(fmt) + b = b.strftime(fmt) + subject = '%s - %s | Phantas.ma' % (a, b) + + extra = models.Week.objects.filter(monday=monday).first() + if extra and extra.title: + subject = '%s | %s' % (extra.title, subject) + return subject + def get_byline(week): extra = models.Week.objects.filter(monday=week).first() if extra: diff --git a/app/listmonk/utils.py b/app/listmonk/utils.py index cb770e6..b7708f5 100644 --- a/app/listmonk/utils.py +++ b/app/listmonk/utils.py @@ -28,7 +28,7 @@ def send_week(monday): year, month, day = monday.split('-') body = views.week(year, month, day) name = 'weekly-digest-%s' % monday - subject = 'Phantas.ma weekly update %s' % views.format_week(monday) + subject = views.format_subject(monday) return send_email(name, subject, body) diff --git a/app/listmonk/views.py b/app/listmonk/views.py index de71841..cd0913a 100644 --- a/app/listmonk/views.py +++ b/app/listmonk/views.py @@ -13,7 +13,7 @@ from django.core.validators import validate_email import django.contrib.auth from ..item import models -from ..item.views import get_weeks, format_week, get_monday, get_byline +from ..item.views import get_weeks, format_week, get_monday, get_byline, format_subject from ..item.utils import render_to_json from ..utils import default_context @@ -40,7 +40,7 @@ def week(year, month, day): context['weeks'] = get_weeks(archive) monday = context['this_week'] = date.strftime('%Y-%m-%d') context['this_year'] = date.strftime('%Y') - context['week_title'] = 'Phantas.ma weekly update %s' % format_week(monday) + context['week_title'] = format_subject(monday) context['week_byline'] = get_byline(monday) context['week_link'] = settings.URL + '/_' + monday context['items'] = archive_week From 845303be622cdc6e03993d63ae2c5413dd885144 Mon Sep 17 00:00:00 2001 From: j Date: Fri, 7 Mar 2025 09:44:30 +0100 Subject: [PATCH 2/2] use textarea for url --- app/item/admin.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/item/admin.py b/app/item/admin.py index 8a5cf79..595ee45 100644 --- a/app/item/admin.py +++ b/app/item/admin.py @@ -15,6 +15,10 @@ class ItemAdmin(admin.ModelAdmin): def get_changeform_initial_data(self, request): return {'user': request.user} + def get_form(self, request, obj=None, **kwargs): + kwargs['widgets'] = {'url': forms.Textarea} + return super().get_form(request, obj, **kwargs) + admin.site.register(models.Item, ItemAdmin)