comparison gpp/forums/views.py @ 89:021492db4aad

Forums: Got the reply function working.
author Brian Neal <bgneal@gmail.com>
date Sat, 12 Sep 2009 21:29:31 +0000
parents 515d1daec811
children 317c7bcaecee
comparison
equal deleted inserted replaced
88:3abf0b045749 89:021492db4aad
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.contrib.auth.decorators import login_required
5 from django.http import Http404 5 from django.http import Http404
6 from django.http import HttpResponseBadRequest
6 from django.http import HttpResponseRedirect 7 from django.http import HttpResponseRedirect
7 from django.core.urlresolvers import reverse 8 from django.core.urlresolvers import reverse
8 from django.shortcuts import get_object_or_404 9 from django.shortcuts import get_object_or_404
9 from django.shortcuts import render_to_response 10 from django.shortcuts import render_to_response
10 from django.template import RequestContext 11 from django.template import RequestContext
12 from django.views.decorators.http import require_POST
11 13
12 from forums.models import Forum 14 from forums.models import Forum
13 from forums.models import Topic 15 from forums.models import Topic
14 from forums.forms import NewTopicForm 16 from forums.forms import NewTopicForm
15 from forums.forms import PostForm 17 from forums.forms import PostForm
65 return render_to_response('forums/topic.html', { 67 return render_to_response('forums/topic.html', {
66 'forum': topic.forum, 68 'forum': topic.forum,
67 'topic': topic, 69 'topic': topic,
68 'posts': posts, 70 'posts': posts,
69 'last_page': last_page, 71 'last_page': last_page,
70 'form': PostForm(), 72 'form': PostForm(initial={'topic_id': topic.id}),
71 }, 73 },
72 context_instance=RequestContext(request)) 74 context_instance=RequestContext(request))
73 75
74 76
75 @login_required 77 @login_required
103 return render_to_response('forums/new_topic_thanks.html', { 105 return render_to_response('forums/new_topic_thanks.html', {
104 'forum': topic.forum, 106 'forum': topic.forum,
105 'topic': topic, 107 'topic': topic,
106 }, 108 },
107 context_instance=RequestContext(request)) 109 context_instance=RequestContext(request))
110
111
112 @login_required
113 @require_POST
114 def quick_reply_ajax(request):
115 """
116 This function handles the quick reply to a thread function. This
117 function is meant to be the target of an AJAX post, and returns
118 the HTML for the new post, which the client-side script appends
119 to the document.
120 """
121 form = PostForm(request.POST)
122 if form.is_valid():
123 post = form.save(request.user, request.META.get("REMOTE_ADDR"))
124 return render_to_response('forums/display_post.html', {
125 'post': post,
126 },
127 context_instance=RequestContext(request))
128
129 return HttpResponseBadRequest();
130