phantasmobile/app/listmonk/views.py
2023-10-15 17:10:38 +01:00

33 lines
1.2 KiB
Python

from django.conf import settings
from django.db.models.functions import ExtractWeek, ExtractYear
from django.shortcuts import render
from django.template.loader import render_to_string
from django.utils import timezone
from django.utils.timezone import datetime, timedelta
from ..item import models
from ..item.views import get_weeks, format_week, get_monday
def week(year, month, day):
now = timezone.make_aware(datetime.now(), timezone.get_default_timezone())
context = {}
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)
archive_week = archive.filter(year=year, week=week).order_by('published')
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_link'] = settings.URL + '/_' + monday
context['items'] = archive_week
return render_to_string("weekly_email.html", context)