diff gpp/antispam/utils.py @ 563:93f049a241ff

For bitbucket issue #4, deactivate users for spam when accepting flagged user profiles. Also use raw_id_fields on UserProfileFlagAdmin.
author Brian Neal <bgneal@gmail.com>
date Thu, 09 Feb 2012 19:38:03 -0600
parents 98b373ca09f3
children
line wrap: on
line diff
--- a/gpp/antispam/utils.py	Wed Feb 08 18:58:57 2012 -0600
+++ b/gpp/antispam/utils.py	Thu Feb 09 19:38:03 2012 -0600
@@ -8,7 +8,9 @@
 from antispam import SPAM_PHRASE_KEY
 from antispam.models import SpamPhrase
 from core.functions import email_admins
-from bio.models import STA_SUSPENDED
+from bio.models import STA_SUSPENDED, STA_SPAMMER
+from comments.models import Comment
+from forums.tools import delete_user_posts
 
 
 def contains_spam(s):
@@ -61,11 +63,36 @@
     profile.status = STA_SUSPENDED
     profile.status_date = datetime.datetime.now()
     profile.save(content_update=False)
+    logging.info("User suspended: %s", user.username)
+
+
+def deactivate_spammer(user):
+    """
+    This function deactivate's the user, marks them as a spammer, then
+    deletes the user's comments and forum posts. The spammer's profile is
+    cleared so any spam links won't show up anymore.
+
+    """
+    user.is_active = False
+    user.save()
+
+    profile = user.get_profile()
+    profile.status = STA_SPAMMER
+    profile.status_date = datetime.datetime.now()
+    profile.reset_text_fields()
+    profile.save()
+
+    Comment.objects.filter(user=user).delete()
+    delete_user_posts(user)
+
+    logging.info("User deactivated for spam: %s", user.username)
 
 
 def _get_spam_phrases():
-    """This function returns the current list of spam phrase strings.
+    """
+    This function returns the current list of spam phrase strings.
     The strings are cached to avoid hitting the database.
+
     """
     phrases = cache.get(SPAM_PHRASE_KEY)
     if phrases: