comparison gpp/bio/admin.py @ 215:8c1832b9d815

Implement #84; additional checks on spammers; implement stranger status.
author Brian Neal <bgneal@gmail.com>
date Sat, 29 May 2010 04:51:28 +0000
parents 8bbefaa3e408
children d424b8bae71d
comparison
equal deleted inserted replaced
214:28988cce138b 215:8c1832b9d815
18 18
19 class UserProfileAdmin(admin.ModelAdmin): 19 class UserProfileAdmin(admin.ModelAdmin):
20 search_fields = ('user__username', 'user__first_name', 'user__last_name', 20 search_fields = ('user__username', 'user__first_name', 'user__last_name',
21 'user__email') 21 'user__email')
22 exclude = ('profile_html', 'signature_html') 22 exclude = ('profile_html', 'signature_html')
23 list_display = ('__unicode__', 'get_status_display', 'status_date') 23 list_display = ('__unicode__', 'user_is_active', 'get_status_display', 'status_date')
24 readonly_fields = ('status', 'status_date')
24 list_filter = ('status', ) 25 list_filter = ('status', )
25 date_hierarchy = 'status_date' 26 date_hierarchy = 'status_date'
26 inlines = (BadgeOwnerInline, ) 27 inlines = (BadgeOwnerInline, )
27 actions = ( 28 actions = (
28 'mark_active', 29 'mark_active',
29 'mark_resigned', 30 'mark_resigned',
30 'mark_removed', 31 'mark_removed',
31 'mark_suspended', 32 'mark_suspended',
32 'mark_spammer', 33 'mark_spammer',
34 'mark_stranger',
33 ) 35 )
34 36
35 def get_status_display(self, obj): 37 def get_status_display(self, obj):
36 return obj.get_status_display() 38 return obj.get_status_display()
37 get_status_display.short_description = 'Status' 39 get_status_display.short_description = 'Status'
42 profiles to 'status'. Updates the status_date. Sets the is_active 44 profiles to 'status'. Updates the status_date. Sets the is_active
43 field to True if the status is STA_ACTIVE and False otherwise. 45 field to True if the status is STA_ACTIVE and False otherwise.
44 """ 46 """
45 now = datetime.datetime.now() 47 now = datetime.datetime.now()
46 for profile in qs: 48 for profile in qs:
47 profile.user.is_active = status == bio.models.STA_ACTIVE 49 profile.user.is_active = (status == bio.models.STA_ACTIVE or
50 status == bio.models.STA_STRANGER)
48 profile.user.save() 51 profile.user.save()
49 profile.status = status 52 profile.status = status
50 profile.status_date = now 53 profile.status_date = now
51 profile.save() 54 profile.save()
52 55
92 for profile in qs: 95 for profile in qs:
93 Comment.objects.filter(user=profile.user).delete() 96 Comment.objects.filter(user=profile.user).delete()
94 delete_user_posts(profile.user) 97 delete_user_posts(profile.user)
95 mark_spammer.short_description = "Mark selected users as spammers" 98 mark_spammer.short_description = "Mark selected users as spammers"
96 99
100 def mark_stranger(self, request, qs):
101 """
102 Marks users as strangers. Updates their profile status to STA_STRANGER.
103 """
104 self.mark_user_status(request, qs, bio.models.STA_STRANGER)
105 mark_stranger.short_description = "Mark selected users as strangers"
106
97 107
98 class UserProfileFlagAdmin(admin.ModelAdmin): 108 class UserProfileFlagAdmin(admin.ModelAdmin):
99 list_display = ('__unicode__', 'flag_date', 'get_profile_url') 109 list_display = ('__unicode__', 'flag_date', 'get_profile_url')
100 actions = ('accept_flags', ) 110 actions = ('accept_flags', )
101 111