lemoncurry/home/views.py

44 lines
1.2 KiB
Python
Raw Normal View History

from annoying.decorators import render_to
2017-10-31 00:10:13 -04:00
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
2017-10-31 00:10:13 -04:00
from django.urls import reverse
2017-10-22 18:37:24 -04:00
from users.models import User
2017-10-31 00:10:13 -04:00
from urllib.parse import urljoin
from entries import kinds
from lemoncurry import breadcrumbs, utils
breadcrumbs.add('home:index', 'home')
2017-10-22 18:37:24 -04:00
@render_to('home/index.html')
def index(request, before=None):
query = User.objects.prefetch_related('entries', 'profiles', 'keys')
user = get_object_or_404(query, pk=1)
entries = user.entries.filter(kind__in=kinds.on_home)
if before:
entries = entries.filter(id__lt=before)
entries = entries[:10]
next = None
if entries:
next = reverse('home:index', kwargs={'before': entries.last().id})
return {
'user': user,
'entries': entries,
'next': next,
'atom': 'entries:atom',
'rss': 'entries:rss',
'meta': user.as_meta(request),
}
2017-10-31 00:10:13 -04:00
def robots(request):
base = utils.origin(request)
lines = (
'User-agent: *',
'Sitemap: {0}'.format(urljoin(base, reverse('sitemap')))
)
return HttpResponse("\n".join(lines) + "\n", content_type='text/plain')