comparison gpp/forums/views.py @ 147:152d77265da6

Implement #38: add function to mark user as a spammer. Display only active members on member list. Display login form as table (not sure why wasn't doing this before).
author Brian Neal <bgneal@gmail.com>
date Sun, 13 Dec 2009 08:11:16 +0000
parents 3ae999b0c53b
children 445e1466a98d
comparison
equal deleted inserted replaced
146:023132c90021 147:152d77265da6
323 request.user in post.topic.forum.moderators.all() 323 request.user in post.topic.forum.moderators.all()
324 324
325 if not can_delete: 325 if not can_delete:
326 return HttpResponseForbidden("You don't have permission to delete that post.") 326 return HttpResponseForbidden("You don't have permission to delete that post.")
327 327
328 delete_single_post(post)
329 return HttpResponse("The post has been deleted.")
330
331
332 def delete_single_post(post):
333 """
334 This function deletes a single post. It handles the case of where
335 a post is the sole post in a topic by deleting the topic also. It
336 adjusts any foreign keys in Topic or Forum objects that might be pointing
337 to this post before deleting the post to avoid a cascading delete.
338 """
328 if post.topic.post_count == 1 and post == post.topic.last_post: 339 if post.topic.post_count == 1 and post == post.topic.last_post:
329 _delete_topic(post.topic) 340 _delete_topic(post.topic)
330 else: 341 else:
331 _delete_post(post) 342 _delete_post(post)
332
333 return HttpResponse("The post has been deleted.")
334 343
335 344
336 def _delete_post(post): 345 def _delete_post(post):
337 """ 346 """
338 Internal function to delete a single post object. 347 Internal function to delete a single post object.
369 Deletes the topic and all posts contained within. 378 Deletes the topic and all posts contained within.
370 Adjusts the parent forum's last_post as needed. 379 Adjusts the parent forum's last_post as needed.
371 Note that we don't bother adjusting all the users' 380 Note that we don't bother adjusting all the users'
372 post counts as that doesn't seem to be worth the effort. 381 post counts as that doesn't seem to be worth the effort.
373 """ 382 """
374 if topic.forum.last_post.topic == topic: 383 if topic.forum.last_post and topic.forum.last_post.topic == topic:
375 topic.forum.last_post_pre_delete() 384 topic.forum.last_post_pre_delete()
376 topic.forum.save() 385 topic.forum.save()
377 386
378 # It should be safe to just delete the topic now. This will 387 # It should be safe to just delete the topic now. This will
379 # automatically delete all posts in the topic. 388 # automatically delete all posts in the topic.