Mercurial > public > sg101
diff comments/admin.py @ 671:be5b37719059
Provide a "fix text" admin function for comments.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 25 May 2013 22:17:46 -0500 |
parents | ee87ea74d46b |
children |
line wrap: on
line diff
--- a/comments/admin.py Sat May 25 17:44:18 2013 -0500 +++ b/comments/admin.py Sat May 25 22:17:46 2013 -0500 @@ -4,28 +4,38 @@ from django.contrib import admin from comments.models import Comment from comments.models import CommentFlag + +import ftfy + import bio.badges + class CommentAdmin(admin.ModelAdmin): - fieldsets = ( - (None, - {'fields': ('content_type', 'object_id', )} - ), - ('Content', - {'fields': ('user', 'comment')} - ), - ('Metadata', - {'fields': ('ip_address', 'is_public', 'is_removed')} - ), - ) - list_display = ('__unicode__', 'content_type', 'object_id', 'ip_address', - 'creation_date', 'is_public', 'not_removed') - list_filter = ('creation_date', 'is_public', 'is_removed') + fieldsets = [ + (None, {'fields': ['content_type', 'object_id']}), + ('Content', {'fields': ['user', 'comment']}), + ('Metadata', {'fields': ['ip_address', 'is_public', 'is_removed']}), + ] + list_display = ['__unicode__', 'content_type', 'object_id', 'ip_address', + 'creation_date', 'is_public', 'not_removed'] + list_filter = ['creation_date', 'is_public', 'is_removed'] date_hierarchy = 'creation_date' - ordering = ('-creation_date', ) - search_fields = ('comment', 'user__username', 'ip_address') - raw_id_fields = ('user', 'content_type') + ordering = ['-creation_date'] + search_fields = ['comment', 'user__username', 'ip_address'] + raw_id_fields = ['user', 'content_type'] + actions = ['fix_text'] + + def fix_text(self, request, qs): + for comment in qs: + comment.comment = ftfy.fix_text(comment.comment) + comment.save() + + count = len(qs) + msg = "1 comment" if count == 1 else "%d comments" % count + self.message_user(request, "Text fixed on {}".format(msg)) + + fix_text.short_description = "Fix text on selected comments" class CommentFlagAdmin(admin.ModelAdmin):