2017-10-28 21:41:33 -04:00
|
|
|
from annoying.decorators import render_to
|
2018-03-06 23:46:21 -05:00
|
|
|
from django.shortcuts import get_object_or_404
|
2017-12-14 20:34:02 -05:00
|
|
|
from django.urls import reverse
|
2018-03-07 21:49:02 -05:00
|
|
|
from .. import kinds
|
2018-03-06 23:46:21 -05:00
|
|
|
from ..models import Entry, Cat
|
|
|
|
from ..pagination import paginate
|
2017-10-24 21:01:52 -04:00
|
|
|
|
|
|
|
|
2017-10-28 21:41:33 -04:00
|
|
|
@render_to('entries/index.html')
|
2018-03-06 23:46:21 -05:00
|
|
|
def by_kind(request, kind, page):
|
2018-03-07 21:49:02 -05:00
|
|
|
kind = kinds.from_plural[kind]
|
2017-12-14 20:34:02 -05:00
|
|
|
entries = Entry.objects.filter(kind=kind.id)
|
2018-03-07 21:49:02 -05:00
|
|
|
entries = paginate(queryset=entries, reverse=kind.index_page, page=page)
|
2017-12-14 20:34:02 -05:00
|
|
|
if hasattr(entries, 'content'):
|
|
|
|
return entries
|
2017-12-12 02:35:13 -05:00
|
|
|
|
2017-10-31 18:29:59 -04:00
|
|
|
return {
|
|
|
|
'entries': entries,
|
2018-03-07 21:49:02 -05:00
|
|
|
'atom': kind.atom,
|
|
|
|
'rss': kind.rss,
|
2017-10-31 18:29:59 -04:00
|
|
|
'title': kind.plural,
|
|
|
|
}
|
2017-10-24 21:31:08 -04:00
|
|
|
|
|
|
|
|
2017-11-19 18:59:03 -05:00
|
|
|
@render_to('entries/index.html')
|
2018-03-06 23:46:21 -05:00
|
|
|
def by_cat(request, slug, page):
|
2017-12-14 20:34:02 -05:00
|
|
|
def url(page):
|
|
|
|
kwargs = {'slug': slug}
|
|
|
|
if page > 1:
|
|
|
|
kwargs['page'] = page
|
|
|
|
return reverse('entries:cat', kwargs=kwargs)
|
|
|
|
|
2017-11-19 19:09:30 -05:00
|
|
|
cat = get_object_or_404(Cat, slug=slug)
|
2017-12-14 20:34:02 -05:00
|
|
|
entries = cat.entries.all()
|
|
|
|
entries = paginate(queryset=entries, reverse=url, page=page)
|
|
|
|
if hasattr(entries, 'content'):
|
|
|
|
return entries
|
2017-12-12 17:56:18 -05:00
|
|
|
|
2017-11-19 18:59:03 -05:00
|
|
|
return {
|
2017-12-12 02:35:13 -05:00
|
|
|
'entries': entries,
|
2017-11-19 19:09:30 -05:00
|
|
|
'title': '#' + cat.name,
|
2017-11-19 18:59:03 -05:00
|
|
|
}
|