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)
|
return json.dumps(comments)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def public(cls):
|
def public(cls, now=None):
|
||||||
now = timezone.now()
|
if now is None:
|
||||||
|
now = timezone.now()
|
||||||
qs = cls.objects.exclude(published=None).filter(published__lte=now).order_by('-published')
|
qs = cls.objects.exclude(published=None).filter(published__lte=now).order_by('-published')
|
||||||
cal = now.date().isocalendar()
|
cal = now.date().isocalendar()
|
||||||
monday = now.date() - timedelta(days=now.date().isocalendar().weekday - 1)
|
monday = now.date() - timedelta(days=now.date().isocalendar().weekday - 1)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
from datetime import date, datetime, timedelta
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from django.utils.timezone import datetime, timedelta
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.utils.html import mark_safe
|
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 render_to_json
|
||||||
from ..utils import default_context
|
from ..utils import default_context
|
||||||
|
|
||||||
|
TS_FORMAT = "%Y-%m-%dT%H:%M:%S"
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
context = default_context(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['items'] = week
|
||||||
context['archive'] = archive.exists()
|
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)
|
return render(request, 'index.html', context)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -98,3 +98,10 @@ nav.overlay {
|
||||||
padding-bottom: 8px;
|
padding-bottom: 8px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.now {
|
||||||
|
background: lightyellow;
|
||||||
|
color: black;
|
||||||
|
padding: 8px;
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
|
@ -40,6 +40,13 @@
|
||||||
<div class="about">
|
<div class="about">
|
||||||
{{ overlay.content | safe }}
|
{{ overlay.content | safe }}
|
||||||
</div>
|
</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">
|
<div class="user">
|
||||||
{% if request.user.is_authenticated %}
|
{% if request.user.is_authenticated %}
|
||||||
<div>You are logged in as {{ request.user.username }}</div>
|
<div>You are logged in as {{ request.user.username }}</div>
|
||||||
|
|
Loading…
Reference in a new issue