Mercurial > public > sg101
comparison gpp/forums/views.py @ 83:5b4c812b448e
Forums: Added the ability to add a new topic. This is very much a work in progress.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 29 Aug 2009 20:54:16 +0000 |
parents | bc3978f023c2 |
children | f81226b5e87b |
comparison
equal
deleted
inserted
replaced
82:bc3978f023c2 | 83:5b4c812b448e |
---|---|
1 """ | 1 """ |
2 Views for the forums application. | 2 Views for the forums application. |
3 """ | 3 """ |
4 from django.contrib.auth.decorators import login_required | |
4 from django.http import Http404 | 5 from django.http import Http404 |
6 from django.http import HttpResponseRedirect | |
7 from django.core.urlresolvers import reverse | |
5 from django.shortcuts import get_object_or_404 | 8 from django.shortcuts import get_object_or_404 |
6 from django.shortcuts import render_to_response | 9 from django.shortcuts import render_to_response |
7 from django.template import RequestContext | 10 from django.template import RequestContext |
8 | 11 |
9 from forums.models import Forum | 12 from forums.models import Forum |
13 from forums.models import Topic | |
14 from forums.forms import NewTopicForm | |
10 | 15 |
11 | 16 |
12 def index(request): | 17 def index(request): |
13 """ | 18 """ |
14 This view displays all the forums available, ordered in each category. | 19 This view displays all the forums available, ordered in each category. |
48 def topic_index(request, id): | 53 def topic_index(request, id): |
49 """ | 54 """ |
50 Displays all the posts in a topic. | 55 Displays all the posts in a topic. |
51 """ | 56 """ |
52 raise Http404 | 57 raise Http404 |
58 | |
59 | |
60 @login_required | |
61 def new_topic(request, slug): | |
62 """ | |
63 This view handles the creation of new topics. | |
64 """ | |
65 forum = get_object_or_404(Forum, slug=slug) | |
66 if request.method == 'POST': | |
67 form = NewTopicForm(request.POST) | |
68 if form.is_valid(): | |
69 topic = form.save(forum, request.user, request.META.get("REMOTE_ADDR")) | |
70 return HttpResponseRedirect(reverse('forums-new_topic_thanks', | |
71 kwargs={'tid': topic.pk})) | |
72 else: | |
73 form = NewTopicForm() | |
74 | |
75 return render_to_response('forums/new_topic.html', { | |
76 'forum': forum, | |
77 'form': form, | |
78 }, | |
79 context_instance=RequestContext(request)) | |
80 | |
81 | |
82 @login_required | |
83 def new_topic_thanks(request, tid): | |
84 """ | |
85 This view displays the success page for a newly created topic. | |
86 """ | |
87 topic = get_object_or_404(Topic, pk=tid) | |
88 return render_to_response('forums/new_topic_thanks.html', { | |
89 'forum': topic.forum, | |
90 'topic': topic, | |
91 }, | |
92 context_instance=RequestContext(request)) |