From 19b9f72ed9223a0f97f595bd886b21949e3c8e9d Mon Sep 17 00:00:00 2001 From: j Date: Mon, 14 Aug 2023 14:10:30 +0200 Subject: [PATCH] shift current week --- app/item/models.py | 5 +++-- app/item/views.py | 17 +++++++++++++++-- app/static/css/site.scss | 7 +++++++ app/templates/base.html | 7 +++++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/item/models.py b/app/item/models.py index de681d0..d514aca 100644 --- a/app/item/models.py +++ b/app/item/models.py @@ -57,8 +57,9 @@ class Item(models.Model): return json.dumps(comments) @classmethod - def public(cls): - now = timezone.now() + def public(cls, now=None): + if now is None: + now = timezone.now() qs = cls.objects.exclude(published=None).filter(published__lte=now).order_by('-published') cal = now.date().isocalendar() monday = now.date() - timedelta(days=now.date().isocalendar().weekday - 1) diff --git a/app/item/views.py b/app/item/views.py index 0e03575..26988b6 100644 --- a/app/item/views.py +++ b/app/item/views.py @@ -1,9 +1,9 @@ import xml.etree.ElementTree as ET -from datetime import date, datetime, timedelta import json from django.utils import timezone +from django.utils.timezone import datetime, timedelta from django.shortcuts import render from django.db.models import Q from django.utils.html import mark_safe @@ -16,12 +16,25 @@ from ..signalbot.rpc import send_reaction from .utils import render_to_json from ..utils import default_context +TS_FORMAT = "%Y-%m-%dT%H:%M:%S" + def index(request): context = default_context(request) - week, archive = models.Item.public() + now = request.GET.get("now") + if request.user.is_staff and now: + now = datetime.strptime(now, TS_FORMAT) + elif request.user.is_staff: + now = datetime.now() + else: + now = None + week, archive = models.Item.public(now) context['items'] = week context['archive'] = archive.exists() + if now: + context['now'] = now + context['previous_week'] = (now - timedelta(days=7)).strftime(TS_FORMAT) + context['next_week'] = (now + timedelta(days=7)).strftime(TS_FORMAT) return render(request, 'index.html', context) diff --git a/app/static/css/site.scss b/app/static/css/site.scss index 87a0227..49fceb3 100644 --- a/app/static/css/site.scss +++ b/app/static/css/site.scss @@ -98,3 +98,10 @@ nav.overlay { padding-bottom: 8px; } } + +.now { + background: lightyellow; + color: black; + padding: 8px; + opacity: 0.8; +} diff --git a/app/templates/base.html b/app/templates/base.html index 4e18837..771aa3b 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -40,6 +40,13 @@
{{ overlay.content | safe }}
+ {% if now %} +
+ previous week + {{ now }} + next week +
+ {% endif %}
{% if request.user.is_authenticated %}
You are logged in as {{ request.user.username }}