view 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 source
"""
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