From 82edae60fbdb25d34a339fa133a105c19b26c07d Mon Sep 17 00:00:00 2001 From: j Date: Tue, 6 Feb 2024 17:47:54 +0100 Subject: [PATCH] byline for week --- app/item/migrations/0009_week_byline.py | 17 +++++++++++++++++ app/item/models.py | 1 + app/item/views.py | 5 +++++ app/listmonk/views.py | 3 ++- app/static/css/site.scss | 24 ++++++++++++++++++++++++ app/templates/archive.html | 9 ++++++++- app/templates/weekly_email.html | 3 +++ 7 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 app/item/migrations/0009_week_byline.py diff --git a/app/item/migrations/0009_week_byline.py b/app/item/migrations/0009_week_byline.py new file mode 100644 index 0000000..ee09179 --- /dev/null +++ b/app/item/migrations/0009_week_byline.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.3 on 2024-02-06 16:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("item", "0008_alter_week_title"), + ] + + operations = [ + migrations.AddField( + model_name="week", + name="byline", + field=models.CharField(blank=True, default="", max_length=2048), + ), + ] diff --git a/app/item/models.py b/app/item/models.py index b9e048e..7355a72 100644 --- a/app/item/models.py +++ b/app/item/models.py @@ -190,6 +190,7 @@ class Week(models.Model): modified = models.DateTimeField(auto_now=True) monday = models.DateField(unique=True) title = models.CharField(max_length=2048, blank=True, default="") + byline = models.CharField(max_length=2048, blank=True, default="") published = models.DateTimeField(null=True, default=None, blank=True, editable=False) def __str__(self): diff --git a/app/item/views.py b/app/item/views.py index fb85cdb..5e59788 100644 --- a/app/item/views.py +++ b/app/item/views.py @@ -42,6 +42,10 @@ def format_week(week): extra = '' return '%s - %s%s' % (a, b, extra) +def get_byline(week): + extra = models.Week.objects.filter(monday=week).first() + if extra: + return extra.byline def get_weeks(archive): weeks = sorted(set(archive.values_list('year', 'week'))) @@ -103,6 +107,7 @@ def archive(request, year=None, month=None, day=None, week=None): extra = models.Week.objects.filter(monday=context['this_week']).first() if extra: context['week_title'] = extra.title + context['week_byline'] = extra.byline elif week: week = int(week) year = int(year) diff --git a/app/listmonk/views.py b/app/listmonk/views.py index c309d33..1fee8a9 100644 --- a/app/listmonk/views.py +++ b/app/listmonk/views.py @@ -7,7 +7,7 @@ from django.utils.timezone import datetime, timedelta from ..item import models -from ..item.views import get_weeks, format_week, get_monday +from ..item.views import get_weeks, format_week, get_monday, get_byline def week(year, month, day): @@ -28,6 +28,7 @@ def week(year, month, day): 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_byline'] = get_byline(monday) context['week_link'] = settings.URL + '/_' + monday context['items'] = archive_week return render_to_string("weekly_email.html", context) diff --git a/app/static/css/site.scss b/app/static/css/site.scss index 5b36129..86bde26 100644 --- a/app/static/css/site.scss +++ b/app/static/css/site.scss @@ -139,6 +139,30 @@ header { padding-bottom: 8px; margin-bottom: 8px; border-bottom: 1px solid blueviolet; + + &.with-byline { + display: flex; + margin-left: 4px; + margin-right: 4px; + div { + flex-grow: 1; + text-align: left; + } + .byline { + text-align: right; + } + @media(max-width:768px) { + display: block; + div { + margin-left: 4px; + margin-right: 4px; + } + .byline { + text-align: left; + margin-left: 0; + } + } + } } .item > a { display: flex; diff --git a/app/templates/archive.html b/app/templates/archive.html index 85b756d..2760125 100644 --- a/app/templates/archive.html +++ b/app/templates/archive.html @@ -5,7 +5,14 @@ {% block content %}
{% if week_title %} -

{{ week_title }}

+ {% endif %} {% for item in items %} {% include "listitem.html" with item=item %} diff --git a/app/templates/weekly_email.html b/app/templates/weekly_email.html index a90b619..6ea8445 100644 --- a/app/templates/weekly_email.html +++ b/app/templates/weekly_email.html @@ -1,5 +1,8 @@ {% if week_title %} {{ week_title }} +{% if week_byline %}
+{{ week_byline }} +{% endif %}

{% endif %}