2017-10-28 21:41:33 -04:00
|
|
|
from annoying.decorators import render_to
|
2017-10-31 00:10:13 -04:00
|
|
|
from django.http import HttpResponse
|
2017-12-14 20:25:55 -05:00
|
|
|
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
|
2017-10-24 09:25:41 -04:00
|
|
|
|
2017-12-14 20:25:55 -05:00
|
|
|
from entries import kinds, pagination
|
2017-11-12 16:54:23 -05:00
|
|
|
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')
|
2018-05-03 22:13:52 -04:00
|
|
|
def index(request, page=None):
|
2017-12-14 20:25:55 -05:00
|
|
|
def url(page):
|
|
|
|
kwargs = {'page': page} if page != 1 else {}
|
|
|
|
return reverse('home:index', kwargs=kwargs)
|
|
|
|
|
2018-01-23 21:18:22 -05:00
|
|
|
user = request.user
|
2018-01-28 16:48:56 -05:00
|
|
|
if not hasattr(user, 'entries'):
|
2018-01-23 21:18:22 -05:00
|
|
|
user = get_object_or_404(User, pk=1)
|
|
|
|
|
|
|
|
entries = user.entries.filter(kind__in=kinds.on_home)
|
2017-12-14 20:25:55 -05:00
|
|
|
entries = pagination.paginate(queryset=entries, reverse=url, page=page)
|
2018-01-23 21:18:22 -05: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,
|
2018-03-07 21:49:02 -05:00
|
|
|
'atom': reverse('entries:atom'),
|
|
|
|
'rss': reverse('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')
|