Mercurial > public > sg101
comparison 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 |
comparison
equal
deleted
inserted
replaced
562:98b373ca09f3 | 563:93f049a241ff |
---|---|
6 from django.core.cache import cache | 6 from django.core.cache import cache |
7 | 7 |
8 from antispam import SPAM_PHRASE_KEY | 8 from antispam import SPAM_PHRASE_KEY |
9 from antispam.models import SpamPhrase | 9 from antispam.models import SpamPhrase |
10 from core.functions import email_admins | 10 from core.functions import email_admins |
11 from bio.models import STA_SUSPENDED | 11 from bio.models import STA_SUSPENDED, STA_SPAMMER |
12 from comments.models import Comment | |
13 from forums.tools import delete_user_posts | |
12 | 14 |
13 | 15 |
14 def contains_spam(s): | 16 def contains_spam(s): |
15 """This function returns True if the supplied string s contains any spam | 17 """This function returns True if the supplied string s contains any spam |
16 phrases and False otherwise. | 18 phrases and False otherwise. |
59 user.save() | 61 user.save() |
60 profile = user.get_profile() | 62 profile = user.get_profile() |
61 profile.status = STA_SUSPENDED | 63 profile.status = STA_SUSPENDED |
62 profile.status_date = datetime.datetime.now() | 64 profile.status_date = datetime.datetime.now() |
63 profile.save(content_update=False) | 65 profile.save(content_update=False) |
66 logging.info("User suspended: %s", user.username) | |
67 | |
68 | |
69 def deactivate_spammer(user): | |
70 """ | |
71 This function deactivate's the user, marks them as a spammer, then | |
72 deletes the user's comments and forum posts. The spammer's profile is | |
73 cleared so any spam links won't show up anymore. | |
74 | |
75 """ | |
76 user.is_active = False | |
77 user.save() | |
78 | |
79 profile = user.get_profile() | |
80 profile.status = STA_SPAMMER | |
81 profile.status_date = datetime.datetime.now() | |
82 profile.reset_text_fields() | |
83 profile.save() | |
84 | |
85 Comment.objects.filter(user=user).delete() | |
86 delete_user_posts(user) | |
87 | |
88 logging.info("User deactivated for spam: %s", user.username) | |
64 | 89 |
65 | 90 |
66 def _get_spam_phrases(): | 91 def _get_spam_phrases(): |
67 """This function returns the current list of spam phrase strings. | 92 """ |
93 This function returns the current list of spam phrase strings. | |
68 The strings are cached to avoid hitting the database. | 94 The strings are cached to avoid hitting the database. |
95 | |
69 """ | 96 """ |
70 phrases = cache.get(SPAM_PHRASE_KEY) | 97 phrases = cache.get(SPAM_PHRASE_KEY) |
71 if phrases: | 98 if phrases: |
72 return phrases | 99 return phrases |
73 | 100 |