comparison gpp/forums/views.py @ 81:e356ea79a7a2

More work on forums. Committing what we got so far.
author Brian Neal <bgneal@gmail.com>
date Sun, 23 Aug 2009 00:14:52 +0000
parents 374b24dd2f9a
children bc3978f023c2
comparison
equal deleted inserted replaced
80:a4fdc4d23b9e 81:e356ea79a7a2
1 # Create your views here. 1 """
2 Views for the forums application.
3 """
4 from django.shortcuts import render_to_response
5 from django.template import RequestContext
6
7 from forums.models import Forum
8
9
10 def index(request):
11 forums = Forum.objects.all().select_related()
12 cats = {}
13 for forum in forums:
14 cat = cats.setdefault(forum.category.id, {
15 'cat': forum.category,
16 'forums': [],
17 })
18 cat['forums'].append(forum)
19
20 cmpdef = lambda a, b: cmp(a['cat'].position, b['cat'].position)
21 cats = sorted(cats.values(), cmpdef)
22
23 return render_to_response('forums/index.html', {
24 'cats': cats,
25 },
26 context_instance=RequestContext(request))
27
28 def forum_index(request, slug):
29 pass