diff 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
line wrap: on
line diff
--- a/gpp/forums/views.py	Wed Dec 09 22:58:05 2009 +0000
+++ b/gpp/forums/views.py	Sun Dec 13 08:11:16 2009 +0000
@@ -325,13 +325,22 @@
     if not can_delete:
         return HttpResponseForbidden("You don't have permission to delete that post.")
 
+    delete_single_post(post)
+    return HttpResponse("The post has been deleted.")
+
+
+def delete_single_post(post):
+    """
+    This function deletes a single post. It handles the case of where
+    a post is the sole post in a topic by deleting the topic also. It
+    adjusts any foreign keys in Topic or Forum objects that might be pointing
+    to this post before deleting the post to avoid a cascading delete.
+    """
     if post.topic.post_count == 1 and post == post.topic.last_post:
         _delete_topic(post.topic)
     else:
         _delete_post(post)
 
-    return HttpResponse("The post has been deleted.")
-
 
 def _delete_post(post):
     """
@@ -371,7 +380,7 @@
     Note that we don't bother adjusting all the users'
     post counts as that doesn't seem to be worth the effort.
     """
-    if topic.forum.last_post.topic == topic:
+    if topic.forum.last_post and topic.forum.last_post.topic == topic:
         topic.forum.last_post_pre_delete()
         topic.forum.save()