2017-10-28 21:41:33 -04:00
|
|
|
from annoying.decorators import render_to
|
2017-11-19 18:59:03 -05:00
|
|
|
from django.shortcuts import get_object_or_404, redirect
|
2017-11-19 19:09:30 -05:00
|
|
|
from .models import Entry, Cat
|
2017-10-24 21:01:52 -04:00
|
|
|
|
|
|
|
|
2017-10-28 21:41:33 -04:00
|
|
|
@render_to('entries/index.html')
|
2017-10-24 21:01:52 -04:00
|
|
|
def index(request, kind):
|
|
|
|
entries = Entry.objects.filter(kind=kind.id)
|
2017-10-31 18:29:59 -04:00
|
|
|
return {
|
|
|
|
'entries': entries,
|
|
|
|
'atom': 'entries:' + kind.atom,
|
|
|
|
'rss': 'entries:' + kind.rss,
|
|
|
|
'title': kind.plural,
|
|
|
|
}
|
2017-10-24 21:31:08 -04:00
|
|
|
|
|
|
|
|
2017-11-19 18:59:03 -05:00
|
|
|
@render_to('entries/index.html')
|
2017-11-19 19:09:30 -05:00
|
|
|
def cat(request, slug):
|
|
|
|
cat = get_object_or_404(Cat, slug=slug)
|
2017-11-19 18:59:03 -05:00
|
|
|
return {
|
2017-11-19 19:09:30 -05:00
|
|
|
'entries': cat.entries.all(),
|
|
|
|
'title': '#' + cat.name,
|
2017-11-19 18:59:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-28 21:41:33 -04:00
|
|
|
@render_to('entries/entry.html')
|
2017-10-24 21:31:08 -04:00
|
|
|
def entry(request, id, slug=None):
|
|
|
|
entry = Entry.objects.get(pk=id)
|
2017-10-27 01:23:31 -04:00
|
|
|
if request.path != entry.url:
|
|
|
|
return redirect(entry.url, permanent=True)
|
2017-10-28 21:41:33 -04:00
|
|
|
return {
|
2017-10-24 21:31:08 -04:00
|
|
|
'entry': entry,
|
2017-10-27 02:45:38 -04:00
|
|
|
'title': entry.title,
|
2017-10-24 23:04:22 -04:00
|
|
|
'meta': entry.as_meta(request)
|
2017-10-28 21:41:33 -04:00
|
|
|
}
|