# HG changeset patch # User Brian Neal # Date 1368669370 18000 # Node ID 84865fcd7c2646e333d74dfcf04ed057f3ce938b # Parent b347a31d12dd6d866a511491276275bd0c2694fe For #45, create admin action to unsubscribe users from topics. diff -r b347a31d12dd -r 84865fcd7c26 bio/admin.py --- a/bio/admin.py Wed May 15 20:13:05 2013 -0500 +++ b/bio/admin.py Wed May 15 20:56:10 2013 -0500 @@ -19,22 +19,23 @@ class UserProfileAdmin(admin.ModelAdmin): - search_fields = ('user__username', 'user__first_name', 'user__last_name', - 'user__email') - exclude = ('profile_html', 'signature_html') - list_display = ('__unicode__', 'user_is_active', 'get_status_display', 'status_date') - readonly_fields = ('status', 'status_date', 'update_date') - list_filter = ('status', ) + search_fields = ['user__username', 'user__first_name', 'user__last_name', + 'user__email'] + exclude = ['profile_html', 'signature_html'] + list_display = ['__unicode__', 'user_is_active', 'get_status_display', 'status_date'] + readonly_fields = ['status', 'status_date', 'update_date'] + list_filter = ['status', ] date_hierarchy = 'status_date' - inlines = (BadgeOwnerInline, ) - actions = ( + inlines = [BadgeOwnerInline, ] + actions = [ 'mark_active', 'mark_resigned', 'mark_removed', 'mark_suspended', 'mark_spammer', 'mark_stranger', - ) + 'unsubscribe_forums', + ] def get_status_display(self, obj): return obj.get_status_display() @@ -109,6 +110,15 @@ self.mark_user_status(request, qs, bio.models.STA_STRANGER) mark_stranger.short_description = "Mark selected users as strangers" + def unsubscribe_forums(self, request, qs): + """Delete users forum topic subscriptions.""" + for profile in qs: + profile.user.subscriptions.clear() + + self.message_user(request, "%s subscription(s) deleted." % qs.count()) + + unsubscribe_forums.short_description = "Delete users' forum subscriptions" + class UserProfileFlagAdmin(admin.ModelAdmin): list_display = ['__unicode__', 'flag_date', 'get_profile_url']