annotate 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 |
rev |
line source |
bgneal@81
|
1 """
|
bgneal@81
|
2 Views for the forums application.
|
bgneal@81
|
3 """
|
bgneal@81
|
4 from django.shortcuts import render_to_response
|
bgneal@81
|
5 from django.template import RequestContext
|
bgneal@81
|
6
|
bgneal@81
|
7 from forums.models import Forum
|
bgneal@81
|
8
|
bgneal@81
|
9
|
bgneal@81
|
10 def index(request):
|
bgneal@81
|
11 forums = Forum.objects.all().select_related()
|
bgneal@81
|
12 cats = {}
|
bgneal@81
|
13 for forum in forums:
|
bgneal@81
|
14 cat = cats.setdefault(forum.category.id, {
|
bgneal@81
|
15 'cat': forum.category,
|
bgneal@81
|
16 'forums': [],
|
bgneal@81
|
17 })
|
bgneal@81
|
18 cat['forums'].append(forum)
|
bgneal@81
|
19
|
bgneal@81
|
20 cmpdef = lambda a, b: cmp(a['cat'].position, b['cat'].position)
|
bgneal@81
|
21 cats = sorted(cats.values(), cmpdef)
|
bgneal@81
|
22
|
bgneal@81
|
23 return render_to_response('forums/index.html', {
|
bgneal@81
|
24 'cats': cats,
|
bgneal@81
|
25 },
|
bgneal@81
|
26 context_instance=RequestContext(request))
|
bgneal@81
|
27
|
bgneal@81
|
28 def forum_index(request, slug):
|
bgneal@81
|
29 pass
|