annotate gpp/bio/admin.py @ 199:217119c87a06

Fix #72: update to 1.1.7 of the MarkItUp! editor.
author Brian Neal <bgneal@gmail.com>
date Sun, 11 Apr 2010 18:56:30 +0000
parents 152d77265da6
children b4305e18d3af
rev   line source
gremmie@1 1 """
gremmie@1 2 This file contains the admin definitions for the bio application.
gremmie@1 3 """
bgneal@147 4 import datetime
gremmie@1 5
gremmie@1 6 from django.contrib import admin
gremmie@1 7 from bio.models import UserProfile
bgneal@138 8 from bio.models import UserProfileFlag
bgneal@147 9 import bio.models
bgneal@147 10 from comments.models import Comment
bgneal@147 11 from forums.tools import delete_user_posts
bgneal@147 12
gremmie@1 13
gremmie@1 14 class UserProfileAdmin(admin.ModelAdmin):
bgneal@138 15 search_fields = ('user__username', 'user__first_name', 'user__last_name',
bgneal@138 16 'user__email')
gremmie@1 17 exclude = ('profile_html', 'signature_html')
bgneal@147 18 list_display = ('__unicode__', 'get_status_display', 'status_date')
bgneal@147 19 list_filter = ('status', )
bgneal@147 20 date_hierarchy = 'status_date'
bgneal@147 21 actions = (
bgneal@147 22 'mark_active',
bgneal@147 23 'mark_resigned',
bgneal@147 24 'mark_removed',
bgneal@147 25 'mark_suspended',
bgneal@147 26 'mark_spammer',
bgneal@147 27 )
bgneal@147 28
bgneal@147 29 def get_status_display(self, obj):
bgneal@147 30 return obj.get_status_display()
bgneal@147 31 get_status_display.short_description = 'Status'
bgneal@147 32
bgneal@147 33 def mark_user_status(self, request, qs, status):
bgneal@147 34 """
bgneal@147 35 Common code for the admin actions. Updates the status field in the
bgneal@147 36 profiles to 'status'. Updates the status_date. Sets the is_active
bgneal@147 37 field to True if the status is STA_ACTIVE and False otherwise.
bgneal@147 38 """
bgneal@147 39 now = datetime.datetime.now()
bgneal@147 40 for profile in qs:
bgneal@147 41 profile.user.is_active = status == bio.models.STA_ACTIVE
bgneal@147 42 profile.user.save()
bgneal@147 43 profile.status = status
bgneal@147 44 profile.status_date = now
bgneal@147 45 profile.save()
bgneal@147 46
bgneal@147 47 count = qs.count()
bgneal@147 48 msg = "1 user" if count == 1 else "%d users" % count
bgneal@147 49 self.message_user(request, "%s successfully marked as %s." % (msg,
bgneal@147 50 bio.models.USER_STATUS_CHOICES[status][1]))
bgneal@147 51
bgneal@147 52 def mark_active(self, request, qs):
bgneal@147 53 """
bgneal@147 54 Marks users as active. Updates their profile status to STA_ACTIVE.
bgneal@147 55 """
bgneal@147 56 self.mark_user_status(request, qs, bio.models.STA_ACTIVE)
bgneal@147 57 mark_active.short_description = "Mark selected users as active"
bgneal@147 58
bgneal@147 59 def mark_resigned(self, request, qs):
bgneal@147 60 """
bgneal@147 61 Marks users as inactive. Updates their profile status to STA_RESIGNED.
bgneal@147 62 """
bgneal@147 63 self.mark_user_status(request, qs, bio.models.STA_RESIGNED)
bgneal@147 64 mark_resigned.short_description = "Mark selected users as resigned"
bgneal@147 65
bgneal@147 66 def mark_removed(self, request, qs):
bgneal@147 67 """
bgneal@147 68 Marks users as inactive. Updates their profile status to STA_REMOVED.
bgneal@147 69 """
bgneal@147 70 self.mark_user_status(request, qs, bio.models.STA_REMOVED)
bgneal@147 71 mark_removed.short_description = "Mark selected users as removed"
bgneal@147 72
bgneal@147 73 def mark_suspended(self, request, qs):
bgneal@147 74 """
bgneal@147 75 Marks users as inactive. Updates their profile status to STA_SUSPENDED.
bgneal@147 76 """
bgneal@147 77 self.mark_user_status(request, qs, bio.models.STA_SUSPENDED)
bgneal@147 78 mark_suspended.short_description = "Mark selected users as suspended"
bgneal@147 79
bgneal@147 80 def mark_spammer(self, request, qs):
bgneal@147 81 """
bgneal@147 82 Marks users as inactive. Updates their profile status to STA_SPAMMER.
bgneal@147 83 Deletes all their comments and forum posts.
bgneal@147 84 """
bgneal@147 85 self.mark_user_status(request, qs, bio.models.STA_SPAMMER)
bgneal@147 86 for profile in qs:
bgneal@147 87 Comment.objects.filter(user=profile.user).delete()
bgneal@147 88 delete_user_posts(profile.user)
bgneal@147 89 mark_spammer.short_description = "Mark selected users as spammers"
gremmie@1 90
bgneal@138 91
bgneal@138 92 class UserProfileFlagAdmin(admin.ModelAdmin):
bgneal@138 93 list_display = ('__unicode__', 'flag_date', 'get_profile_url')
bgneal@138 94
bgneal@138 95
gremmie@1 96 admin.site.register(UserProfile, UserProfileAdmin)
bgneal@138 97 admin.site.register(UserProfileFlag, UserProfileFlagAdmin)