phantasmobile/app/listmonk/views.py

35 lines
1.3 KiB
Python
Raw Normal View History

2023-10-15 16:10:38 +00:00
from django.conf import settings
from django.db.models.functions import ExtractWeek, ExtractYear
2023-09-23 12:38:28 +00:00
from django.shortcuts import render
from django.template.loader import render_to_string
2023-09-23 12:58:41 +00:00
from django.utils import timezone
2023-10-15 16:10:38 +00:00
from django.utils.timezone import datetime, timedelta
2023-09-23 12:58:41 +00:00
2023-09-23 12:38:28 +00:00
from ..item import models
2024-02-06 16:47:54 +00:00
from ..item.views import get_weeks, format_week, get_monday, get_byline
2023-09-23 12:38:28 +00:00
def week(year, month, day):
2023-09-23 12:58:41 +00:00
now = timezone.make_aware(datetime.now(), timezone.get_default_timezone())
2023-09-23 12:38:28 +00:00
context = {}
2023-09-23 12:58:41 +00:00
archive = models.Item.objects.filter(
published__lte=now
).annotate(
year=ExtractYear('published')
).annotate(
week=ExtractWeek('published')
)
2023-09-23 12:38:28 +00:00
date = datetime.strptime('%s-%s-%s' % (year, month, day), '%Y-%m-%d')
week = int(date.strftime('%W'))
year = int(year)
archive_week = archive.filter(year=year, week=week).order_by('published')
context['weeks'] = get_weeks(archive)
2023-09-23 15:30:03 +00:00
monday = context['this_week'] = date.strftime('%Y-%m-%d')
2023-09-23 12:38:28 +00:00
context['this_year'] = date.strftime('%Y')
2023-09-23 15:30:45 +00:00
context['week_title'] = 'Phantas.ma weekly update %s' % format_week(monday)
2024-02-06 16:47:54 +00:00
context['week_byline'] = get_byline(monday)
2023-10-01 07:16:27 +00:00
context['week_link'] = settings.URL + '/_' + monday
2023-09-23 12:38:28 +00:00
context['items'] = archive_week
return render_to_string("weekly_email.html", context)