lemoncurry/entries/views.py

36 lines
892 B
Python
Raw Permalink Normal View History

from annoying.decorators import render_to
from django.shortcuts import get_object_or_404, redirect
from .models import Entry, Cat
@render_to('entries/index.html')
def index(request, kind):
entries = Entry.objects.filter(kind=kind.id)
return {
'entries': entries,
'atom': 'entries:' + kind.atom,
'rss': 'entries:' + kind.rss,
'title': kind.plural,
}
@render_to('entries/index.html')
def cat(request, slug):
cat = get_object_or_404(Cat, slug=slug)
return {
'entries': cat.entries.all(),
'title': '#' + cat.name,
}
@render_to('entries/entry.html')
def entry(request, id, slug=None):
entry = Entry.objects.get(pk=id)
if request.path != entry.url:
return redirect(entry.url, permanent=True)
return {
'entry': entry,
'title': entry.title,
'meta': entry.as_meta(request)
}