2017-10-28 21:41:33 -04:00
|
|
|
from annoying.decorators import render_to
|
2017-12-12 17:56:18 -05:00
|
|
|
from django.core.paginator import Paginator
|
2017-10-31 00:10:13 -04:00
|
|
|
from django.http import HttpResponse
|
2017-12-12 17:56:18 -05:00
|
|
|
from django.shortcuts import get_object_or_404, redirect
|
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
|
2017-10-24 09:25:41 -04:00
|
|
|
|
2017-11-12 16:54:23 -05:00
|
|
|
from entries import kinds
|
|
|
|
from lemoncurry import breadcrumbs, utils
|
|
|
|
|
2017-10-24 09:25:41 -04:00
|
|
|
breadcrumbs.add('home:index', 'home')
|
2017-10-22 18:37:24 -04:00
|
|
|
|
|
|
|
|
2017-10-28 21:41:33 -04:00
|
|
|
@render_to('home/index.html')
|
2017-12-12 17:56:18 -05:00
|
|
|
def index(request, page):
|
2017-10-26 17:52:26 -04:00
|
|
|
query = User.objects.prefetch_related('entries', 'profiles', 'keys')
|
|
|
|
user = get_object_or_404(query, pk=1)
|
2017-12-12 17:56:18 -05:00
|
|
|
paginator = Paginator(user.entries.filter(kind__in=kinds.on_home), 10)
|
2017-12-12 02:35:13 -05:00
|
|
|
|
2017-12-12 17:56:18 -05:00
|
|
|
# If we explicitly got /page/1 in the URL then redirect to the version with
|
|
|
|
# no page suffix.
|
|
|
|
if page == '1':
|
|
|
|
return redirect('home:index', permanent=True)
|
|
|
|
entries = paginator.page(page or 1)
|
2017-10-26 18:52:03 -04:00
|
|
|
|
2017-10-28 21:41:33 -04:00
|
|
|
return {
|
2017-10-24 06:57:07 -04:00
|
|
|
'user': user,
|
2017-11-12 16:54:23 -05:00
|
|
|
'entries': entries,
|
2017-10-31 18:29:59 -04:00
|
|
|
'atom': 'entries:atom',
|
|
|
|
'rss': 'entries:rss',
|
2017-10-24 06:57:07 -04:00
|
|
|
'meta': user.as_meta(request),
|
2017-10-28 21:41:33 -04:00
|
|
|
}
|
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')
|