comparison gpp/forums/views/spam.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
11 from django.shortcuts import get_object_or_404 11 from django.shortcuts import get_object_or_404
12 from django.shortcuts import render_to_response 12 from django.shortcuts import render_to_response
13 from django.template import RequestContext 13 from django.template import RequestContext
14 from django.contrib.auth.models import User 14 from django.contrib.auth.models import User
15 15
16 from comments.models import Comment
17 from forums.models import Post 16 from forums.models import Post
18 from forums.tools import delete_user_posts
19 import forums.permissions as perms 17 import forums.permissions as perms
20 import bio.models 18 import bio.models
21 from core.functions import email_admins 19 from core.functions import email_admins
20 from antispam.utils import deactivate_spammer
22 21
23 22
24 SPAMMER_NAILED_SUBJECT = "Spammer Nailed: %s" 23 SPAMMER_NAILED_SUBJECT = "Spammer Nailed: %s"
25 SPAMMER_NAILED_MSG_BODY = """ 24 SPAMMER_NAILED_MSG_BODY = """
26 The admin/moderator user %s has just deactivated the account of %s for spam. 25 The admin/moderator user %s has just deactivated the account of %s for spam.
27 """ 26 """
28
29 def deactivate_spammer(user):
30 """This function deactivate's the user, marks them as a spammer, then
31 deletes the user's comments and forum posts. The spammer's profile is
32 cleared so any spam links won't show up anymore.
33 """
34 user.is_active = False
35 user.save()
36
37 profile = user.get_profile()
38 profile.status = bio.models.STA_SPAMMER
39 profile.status_date = datetime.datetime.now()
40 profile.reset_text_fields()
41 profile.save()
42
43 Comment.objects.filter(user=user).delete()
44 delete_user_posts(user)
45 27
46 28
47 def promote_stranger(user): 29 def promote_stranger(user):
48 """This function upgrades the user from stranger status to a regular user. 30 """This function upgrades the user from stranger status to a regular user.
49 """ 31 """