diff 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
line wrap: on
line diff
--- a/gpp/forums/views.py	Sun Jul 12 18:25:26 2009 +0000
+++ b/gpp/forums/views.py	Sun Aug 23 00:14:52 2009 +0000
@@ -1,1 +1,29 @@
-# Create your views here.
+"""
+Views for the forums application.
+"""
+from django.shortcuts import render_to_response
+from django.template import RequestContext
+
+from forums.models import Forum
+
+
+def index(request):
+    forums = Forum.objects.all().select_related()
+    cats = {}
+    for forum in forums:
+        cat = cats.setdefault(forum.category.id, {
+            'cat': forum.category,
+            'forums': [],
+            })
+        cat['forums'].append(forum)
+
+    cmpdef = lambda a, b: cmp(a['cat'].position, b['cat'].position)
+    cats = sorted(cats.values(), cmpdef)
+
+    return render_to_response('forums/index.html', {
+        'cats': cats,
+        },
+        context_instance=RequestContext(request))
+
+def forum_index(request, slug):
+    pass