Compare commits

..

No commits in common. "19b9f72ed9223a0f97f595bd886b21949e3c8e9d" and "310cf4659d67b809d9451160097858d807eeef38" have entirely different histories.

5 changed files with 11 additions and 77 deletions

View file

@ -57,9 +57,8 @@ class Item(models.Model):
return json.dumps(comments) return json.dumps(comments)
@classmethod @classmethod
def public(cls, now=None): def public(cls):
if now is None: now = timezone.now()
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)

View file

@ -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,25 +16,12 @@ 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)
now = request.GET.get("now") week, archive = models.Item.public()
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)

View file

@ -98,10 +98,3 @@ nav.overlay {
padding-bottom: 8px; padding-bottom: 8px;
} }
} }
.now {
background: lightyellow;
color: black;
padding: 8px;
opacity: 0.8;
}

View file

@ -40,13 +40,6 @@
<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>

View file

@ -1,6 +1,3 @@
import xml.etree.ElementTree as ET
from django.utils.timezone import datetime, timedelta
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
@ -8,52 +5,17 @@ from django.http import HttpResponse
def robots_txt(request): def robots_txt(request):
txt = '''User-agent: * txt = '''User-agent: *
Disallow: Disallow:
'''
return HttpResponse(txt, 'text/plain')
txt = '''User-agent: *
Disallow:
Sitemap: {} Sitemap: {}
'''.format(request.build_absolute_uri('/sitemap.xml')) '''.format(request.build_absolute_uri('/sitemap.xml'))
return HttpResponse(txt, 'text/plain') return HttpResponse(txt, 'text/plain')
def sitemap_xml(request): def sitemap_xml(request):
now = datetime.now() sitemap = ''
from .item.models import Item return HttpResponse(sitemap, 'application/xml')
urlset = ET.Element('urlset')
urlset.attrib['xmlns'] = "http://www.sitemaps.org/schemas/sitemap/0.9"
urlset.attrib['xmlns:xsi'] = "http://www.w3.org/2001/XMLSchema-instance"
urlset.attrib['xsi:schemaLocation'] = "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
url = ET.SubElement(urlset, "url")
loc = ET.SubElement(url, "loc")
loc.text = request.build_absolute_uri('/')
lastmod = ET.SubElement(url, "lastmod")
lastmod.text = now.strftime("%Y-%m-%d")
changefreq = ET.SubElement(url, "changefreq")
changefreq.text = 'hourly'
priority = ET.SubElement(url, "priority")
priority.text = '1.0'
url = ET.SubElement(urlset, "url")
loc = ET.SubElement(url, "loc")
loc.text = request.build_absolute_uri('/archive/')
lastmod = ET.SubElement(url, "lastmod")
lastmod.text = now.strftime("%Y-%m-%d")
changefreq = ET.SubElement(url, "changefreq")
changefreq.text = 'weekly'
priority = ET.SubElement(url, "priority")
priority.text = '1.0'
for item in Item.objects.exclude(published=None).exclude(published__gt=now).order_by('-published'):
url = ET.SubElement(urlset, "url")
loc = ET.SubElement(url, "loc")
loc.text = request.build_absolute_uri(item.get_absolute_url())
# This date should be in W3C Datetime format, can be %Y-%m-%d
lastmod = ET.SubElement(url, "lastmod")
lastmod.text = item.modified.strftime("%Y-%m-%d")
# always, hourly, daily, weekly, monthly, yearly, never
changefreq = ET.SubElement(url, "changefreq")
changefreq.text = 'daily'
# priority of page on site values 0.1 - 1.0
priority = ET.SubElement(url, "priority")
priority.text = '0.9'
data = b'<?xml version="1.0" encoding="UTF-8"?>\n' + ET.tostring(urlset)
return HttpResponse(data, 'application/xml')