diff --git a/app/item/models.py b/app/item/models.py index b9e160c..1d7baec 100644 --- a/app/item/models.py +++ b/app/item/models.py @@ -97,6 +97,9 @@ class Item(models.Model): def get_absolute_url(self): return reverse('item', kwargs={'id': self.id}) + def full_url(self): + return settings.URL + self.get_absolute_url() + def update_data(self): self.data.update(self.parse_url()) diff --git a/app/listmonk/utils.py b/app/listmonk/utils.py index 97d07cf..3a0874e 100644 --- a/app/listmonk/utils.py +++ b/app/listmonk/utils.py @@ -10,10 +10,12 @@ logger = logging.getLogger(__name__) def send_week(year, month, day): from . import views + date = '%s-%02d-%02d' % (year, month, day) + date = datetime.strptime(date, '%Y-%m-%d') + monday = views.get_monday(date) body = views.week(year, month, day) - week = '%s-%02d-%02d' % (year, month, day) - name = 'weekly-digest-%s' % week - subject = 'Phantas.ma weekly update %s' % views.format_week(week) + name = 'weekly-digest-%s' % monday + subject = 'Phantas.ma weekly update %s' % views.format_week(monday) return send_email(name, subject, body) diff --git a/app/listmonk/views.py b/app/listmonk/views.py index 249bd51..7d901c7 100644 --- a/app/listmonk/views.py +++ b/app/listmonk/views.py @@ -1,14 +1,24 @@ from django.shortcuts import render from django.template.loader import render_to_string from django.utils.timezone import datetime, timedelta +from django.utils import timezone +from django.db.models.functions import ExtractWeek, ExtractYear + from ..item import models from ..item.views import get_weeks def week(year, month, day): + now = timezone.make_aware(datetime.now(), timezone.get_default_timezone()) context = {} - _, archive = models.Item.public() + archive = models.Item.objects.filter( + published__lte=now + ).annotate( + year=ExtractYear('published') + ).annotate( + week=ExtractWeek('published') + ) date = datetime.strptime('%s-%s-%s' % (year, month, day), '%Y-%m-%d') week = int(date.strftime('%W')) year = int(year) diff --git a/app/templates/weekly_email.html b/app/templates/weekly_email.html index 8533d39..0bdc1a2 100644 --- a/app/templates/weekly_email.html +++ b/app/templates/weekly_email.html @@ -7,10 +7,9 @@

{{ item.title }}

{{ item.data.title }}

-
{{ item.full_url }}
- +