shift current week
This commit is contained in:
parent
12b4bc1fbd
commit
19b9f72ed9
4 changed files with 32 additions and 4 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -98,3 +98,10 @@ nav.overlay {
|
|||
padding-bottom: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.now {
|
||||
background: lightyellow;
|
||||
color: black;
|
||||
padding: 8px;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
|
|
@ -40,6 +40,13 @@
|
|||
<div class="about">
|
||||
{{ overlay.content | safe }}
|
||||
</div>
|
||||
{% if now %}
|
||||
<div class="now">
|
||||
<a href="?now={{ previous_week }}">previous week</a>
|
||||
{{ now }}
|
||||
<a href="?now={{ next_week }}">next week</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="user">
|
||||
{% if request.user.is_authenticated %}
|
||||
<div>You are logged in as {{ request.user.username }}</div>
|
||||
|
|
Loading…
Reference in a new issue