diff 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
line wrap: on
line diff
--- a/gpp/forums/views.py	Sun Aug 23 04:04:29 2009 +0000
+++ b/gpp/forums/views.py	Sat Aug 29 20:54:16 2009 +0000
@@ -1,12 +1,17 @@
 """
 Views for the forums application.
 """
+from django.contrib.auth.decorators import login_required
 from django.http import Http404
+from django.http import HttpResponseRedirect
+from django.core.urlresolvers import reverse
 from django.shortcuts import get_object_or_404
 from django.shortcuts import render_to_response
 from django.template import RequestContext
 
 from forums.models import Forum
+from forums.models import Topic
+from forums.forms import NewTopicForm
 
 
 def index(request):
@@ -50,3 +55,38 @@
     Displays all the posts in a topic.
     """
     raise Http404
+
+
+@login_required
+def new_topic(request, slug):
+    """
+    This view handles the creation of new topics.
+    """
+    forum = get_object_or_404(Forum, slug=slug)
+    if request.method == 'POST':
+        form = NewTopicForm(request.POST)
+        if form.is_valid():
+            topic = form.save(forum, request.user, request.META.get("REMOTE_ADDR"))
+            return HttpResponseRedirect(reverse('forums-new_topic_thanks',
+                                            kwargs={'tid': topic.pk}))
+    else:
+        form = NewTopicForm()
+    
+    return render_to_response('forums/new_topic.html', {
+        'forum': forum,
+        'form': form,
+        },
+        context_instance=RequestContext(request))
+
+
+@login_required
+def new_topic_thanks(request, tid):
+    """
+    This view displays the success page for a newly created topic.
+    """
+    topic = get_object_or_404(Topic, pk=tid)
+    return render_to_response('forums/new_topic_thanks.html', {
+        'forum': topic.forum,
+        'topic': topic,
+        },
+        context_instance=RequestContext(request))