comparison gpp/bio/admin.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
8 import django.contrib.auth.models 8 import django.contrib.auth.models
9 import django.contrib.auth.admin 9 import django.contrib.auth.admin
10 10
11 import bio.models 11 import bio.models
12 import bio.badges 12 import bio.badges
13 from comments.models import Comment 13 from antispam.utils import deactivate_spammer
14 from forums.tools import delete_user_posts
15 14
16 15
17 class BadgeOwnerInline(admin.TabularInline): 16 class BadgeOwnerInline(admin.TabularInline):
18 model = bio.models.BadgeOwnership 17 model = bio.models.BadgeOwnership
19 extra = 1 18 extra = 1
89 self.mark_user_status(request, qs, bio.models.STA_SUSPENDED) 88 self.mark_user_status(request, qs, bio.models.STA_SUSPENDED)
90 mark_suspended.short_description = "Mark selected users as suspended" 89 mark_suspended.short_description = "Mark selected users as suspended"
91 90
92 def mark_spammer(self, request, qs): 91 def mark_spammer(self, request, qs):
93 """ 92 """
94 Marks users as inactive. Updates their profile status to STA_SPAMMER. 93 Calls deactivate_spammer() on each user in the profile queryset.
95 Deletes all their comments and forum posts. 94
96 """ 95 """
97 self.mark_user_status(request, qs, bio.models.STA_SPAMMER) 96 count = qs.count()
98 for profile in qs: 97 for profile in qs:
99 Comment.objects.filter(user=profile.user).delete() 98 deactivate_spammer(profile.user)
100 delete_user_posts(profile.user) 99
101 profile.reset_text_fields() 100 self.message_user(request,
102 profile.save() 101 "%s profile(s) successfully marked as spammers." % count)
102
103 mark_spammer.short_description = "Mark selected users as spammers" 103 mark_spammer.short_description = "Mark selected users as spammers"
104 104
105 def mark_stranger(self, request, qs): 105 def mark_stranger(self, request, qs):
106 """ 106 """
107 Marks users as strangers. Updates their profile status to STA_STRANGER. 107 Marks users as strangers. Updates their profile status to STA_STRANGER.
109 self.mark_user_status(request, qs, bio.models.STA_STRANGER) 109 self.mark_user_status(request, qs, bio.models.STA_STRANGER)
110 mark_stranger.short_description = "Mark selected users as strangers" 110 mark_stranger.short_description = "Mark selected users as strangers"
111 111
112 112
113 class UserProfileFlagAdmin(admin.ModelAdmin): 113 class UserProfileFlagAdmin(admin.ModelAdmin):
114 list_display = ('__unicode__', 'flag_date', 'get_profile_url') 114 list_display = ['__unicode__', 'flag_date', 'get_profile_url']
115 actions = ('accept_flags', ) 115 actions = ['accept_flags']
116 raw_id_fields = ['user', 'profile']
116 117
117 def accept_flags(self, request, qs): 118 def accept_flags(self, request, qs):
118 """This action awards a security pin to the user that reported the
119 profile and then deletes the flag.
120 """ 119 """
120 This action awards a security pin to the user that reported the
121 profile, deletes the flags, then deactivates the spammers.
122 """
123 count = qs.count()
121 for flag in qs: 124 for flag in qs:
125 deactivate_spammer(flag.profile.user)
122 bio.badges.award_badge(bio.badges.SECURITY_PIN, flag.user) 126 bio.badges.award_badge(bio.badges.SECURITY_PIN, flag.user)
123 flag.delete() 127 flag.delete()
124 128
125 accept_flags.short_description = "Accept selected flagged profiles" 129 self.message_user(request,
130 "%s profile(s) successfully marked as spammers." % count)
131
132 accept_flags.short_description = "Mark selected profiles as spammers"
126 133
127 134
128 class BadgeAdmin(admin.ModelAdmin): 135 class BadgeAdmin(admin.ModelAdmin):
129 list_display = ('name', 'html', 'order', 'numeric_id', 'description') 136 list_display = ('name', 'html', 'order', 'numeric_id', 'description')
130 list_editable = ('order', 'numeric_id') 137 list_editable = ('order', 'numeric_id')