lemoncurry/home/views.py

39 lines
1.1 KiB
Python
Raw Permalink 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, pagination
from lemoncurry import breadcrumbs, utils
2023-08-10 02:52:37 -04:00
breadcrumbs.add("home:index", "home")
2017-10-22 18:37:24 -04:00
2023-08-10 02:52:37 -04:00
@render_to("home/index.html")
def index(request, page=None):
def url(page):
2023-08-10 02:52:37 -04:00
kwargs = {"page": page} if page != 1 else {}
return reverse("home:index", kwargs=kwargs)
user = request.user
2023-08-10 02:52:37 -04:00
if not hasattr(user, "entries"):
user = get_object_or_404(User, pk=1)
entries = user.entries.filter(kind__in=kinds.on_home)
entries = pagination.paginate(queryset=entries, reverse=url, page=page)
return {
2023-08-10 02:52:37 -04:00
"user": user,
"entries": entries,
"atom": reverse("entries:atom"),
"rss": reverse("entries:rss"),
}
2017-10-31 00:10:13 -04:00
def robots(request):
base = utils.origin(request)
2023-08-10 02:52:37 -04:00
lines = ("User-agent: *", "Sitemap: {0}".format(urljoin(base, reverse("sitemap"))))
return HttpResponse("\n".join(lines) + "\n", content_type="text/plain")