From c6445ac14b23da2af3ff6b16664da66ef6db164a Mon Sep 17 00:00:00 2001 From: Bryan Date: Mon, 13 Jan 2014 23:11:30 -0500 Subject: [PATCH] batch show/hide notes, closes #269 --- karmaworld/apps/moderation/admin.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/karmaworld/apps/moderation/admin.py b/karmaworld/apps/moderation/admin.py index 58104cc..2f223af 100644 --- a/karmaworld/apps/moderation/admin.py +++ b/karmaworld/apps/moderation/admin.py @@ -9,12 +9,26 @@ from karmaworld.apps.notes.models import Note from karmaworld.apps.notes.admin import NoteAdmin from karmaworld.apps.moderation import moderator + # Create a simple action to reset flags to zero. # https://docs.djangoproject.com/en/1.4/ref/contrib/admin/actions/ def reset_flags(modeladmin, request, queryset): queryset.update(flags=0) reset_flags.short_description = "Reset flags to 0" + +# Create a simple action to set is_hidden +def hide_notes(modeladmin, request, queryset): + queryset.update(is_hidden=True) +hide_notes.short_description = "Hide selected notes" + + +# Create a simple action to unset is_hidden +def show_notes(modeladmin, request, queryset): + queryset.update(is_hidden=False) +show_notes.short_description = "Show selected notes" + + # Structure views of Course objects class CourseModerator(CourseAdmin): date_heirarchy = 'updated_at' @@ -25,15 +39,17 @@ class CourseModerator(CourseAdmin): # Enable resetting flags actions = (reset_flags,) + # Structure views of Note objects class NoteModerator(NoteAdmin): date_heirarchy = 'uploaded_at' # Identify fields to display on the Change page - list_display = ('name', 'flags', 'course', 'uploaded_at', 'ip') + list_display = ('name', 'flags', 'course', 'is_hidden', 'uploaded_at', 'ip') # Sort by highest number of flags first, and then by date for ties ordering = ('-flags', '-uploaded_at') # Enable resetting flags - actions = (reset_flags,) + actions = (reset_flags, hide_notes, show_notes) + moderator.site.register(Course, CourseModerator) moderator.site.register(Note, NoteModerator) -- 2.25.1