Mercurial > public > sg101
comparison gpp/forums/views.py @ 82:bc3978f023c2
Forums: started the ability to display topics inside a forum.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 23 Aug 2009 04:04:29 +0000 |
parents | e356ea79a7a2 |
children | 5b4c812b448e |
comparison
equal
deleted
inserted
replaced
81:e356ea79a7a2 | 82:bc3978f023c2 |
---|---|
1 """ | 1 """ |
2 Views for the forums application. | 2 Views for the forums application. |
3 """ | 3 """ |
4 from django.http import Http404 | |
5 from django.shortcuts import get_object_or_404 | |
4 from django.shortcuts import render_to_response | 6 from django.shortcuts import render_to_response |
5 from django.template import RequestContext | 7 from django.template import RequestContext |
6 | 8 |
7 from forums.models import Forum | 9 from forums.models import Forum |
8 | 10 |
9 | 11 |
10 def index(request): | 12 def index(request): |
13 """ | |
14 This view displays all the forums available, ordered in each category. | |
15 """ | |
11 forums = Forum.objects.all().select_related() | 16 forums = Forum.objects.all().select_related() |
12 cats = {} | 17 cats = {} |
13 for forum in forums: | 18 for forum in forums: |
14 cat = cats.setdefault(forum.category.id, { | 19 cat = cats.setdefault(forum.category.id, { |
15 'cat': forum.category, | 20 'cat': forum.category, |
23 return render_to_response('forums/index.html', { | 28 return render_to_response('forums/index.html', { |
24 'cats': cats, | 29 'cats': cats, |
25 }, | 30 }, |
26 context_instance=RequestContext(request)) | 31 context_instance=RequestContext(request)) |
27 | 32 |
33 | |
28 def forum_index(request, slug): | 34 def forum_index(request, slug): |
29 pass | 35 """ |
36 Displays all the topics in a forum. | |
37 """ | |
38 forum = get_object_or_404(Forum, slug=slug) | |
39 topics = forum.topics.select_related() | |
40 | |
41 return render_to_response('forums/forum_index.html', { | |
42 'forum': forum, | |
43 'topics': topics, | |
44 }, | |
45 context_instance=RequestContext(request)) | |
46 | |
47 | |
48 def topic_index(request, id): | |
49 """ | |
50 Displays all the posts in a topic. | |
51 """ | |
52 raise Http404 |