comparison gpp/forums/views/main.py @ 295:26fc9ac9a0eb

Fixing #133; add the ability to edit a topic's title when you edit the first post in that topic.
author Brian Neal <bgneal@gmail.com>
date Sat, 08 Jan 2011 22:04:54 +0000
parents c92fb89dbc7d
children 4f032a6e21f8
comparison
equal deleted inserted replaced
294:254db4cb6a86 295:26fc9ac9a0eb
362 can_edit = can_moderate or request.user == post.user 362 can_edit = can_moderate or request.user == post.user
363 363
364 if not can_edit: 364 if not can_edit:
365 return HttpResponseForbidden("You don't have permission to edit that post.") 365 return HttpResponseForbidden("You don't have permission to edit that post.")
366 366
367 topic_name = None
368 first_post = Post.objects.filter(topic=post.topic).order_by('creation_date')[0]
369 if first_post.id == post.id:
370 topic_name = post.topic.name
371
367 if request.method == "POST": 372 if request.method == "POST":
368 form = PostForm(request.POST, instance=post) 373 form = PostForm(request.POST, instance=post, topic_name=topic_name)
369 if form.is_valid(): 374 if form.is_valid():
370 if antispam.utils.spam_check(request, form.cleaned_data['body']): 375 if antispam.utils.spam_check(request, form.cleaned_data['body']):
371 return HttpResponseRedirect(reverse('antispam-suspended')) 376 return HttpResponseRedirect(reverse('antispam-suspended'))
372 post = form.save(commit=False) 377 post = form.save(commit=False)
373 post.touch() 378 post.touch()
374 post.save() 379 post.save()
375 380
381 # if we are editing a first post, save the parent topic as well
382 if topic_name:
383 post.topic.save()
384
376 # Save any attachments 385 # Save any attachments
377 form.attach_proc.save_attachments(post) 386 form.attach_proc.save_attachments(post)
378 387
379 return HttpResponseRedirect(post.get_absolute_url()) 388 return HttpResponseRedirect(post.get_absolute_url())
380 else: 389 else:
381 form = PostForm(instance=post) 390 form = PostForm(instance=post, topic_name=topic_name)
382 391
383 post.user_profile = request.user.get_profile() 392 post.user_profile = request.user.get_profile()
384 393
385 return render_to_response('forums/edit_post.html', { 394 return render_to_response('forums/edit_post.html', {
386 'forum': post.topic.forum, 395 'forum': post.topic.forum,