bgneal@81: """ bgneal@81: Views for the forums application. bgneal@81: """ bgneal@82: from django.http import Http404 bgneal@82: from django.shortcuts import get_object_or_404 bgneal@81: from django.shortcuts import render_to_response bgneal@81: from django.template import RequestContext bgneal@81: bgneal@81: from forums.models import Forum bgneal@81: bgneal@81: bgneal@81: def index(request): bgneal@82: """ bgneal@82: This view displays all the forums available, ordered in each category. bgneal@82: """ bgneal@81: forums = Forum.objects.all().select_related() bgneal@81: cats = {} bgneal@81: for forum in forums: bgneal@81: cat = cats.setdefault(forum.category.id, { bgneal@81: 'cat': forum.category, bgneal@81: 'forums': [], bgneal@81: }) bgneal@81: cat['forums'].append(forum) bgneal@81: bgneal@81: cmpdef = lambda a, b: cmp(a['cat'].position, b['cat'].position) bgneal@81: cats = sorted(cats.values(), cmpdef) bgneal@81: bgneal@81: return render_to_response('forums/index.html', { bgneal@81: 'cats': cats, bgneal@81: }, bgneal@81: context_instance=RequestContext(request)) bgneal@81: bgneal@82: bgneal@81: def forum_index(request, slug): bgneal@82: """ bgneal@82: Displays all the topics in a forum. bgneal@82: """ bgneal@82: forum = get_object_or_404(Forum, slug=slug) bgneal@82: topics = forum.topics.select_related() bgneal@82: bgneal@82: return render_to_response('forums/forum_index.html', { bgneal@82: 'forum': forum, bgneal@82: 'topics': topics, bgneal@82: }, bgneal@82: context_instance=RequestContext(request)) bgneal@82: bgneal@82: bgneal@82: def topic_index(request, id): bgneal@82: """ bgneal@82: Displays all the posts in a topic. bgneal@82: """ bgneal@82: raise Http404