comparison 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
comparison
equal deleted inserted replaced
670:c5c0f8604c4b 671:be5b37719059
2 This file contains the automatic admin site definitions for the comment models. 2 This file contains the automatic admin site definitions for the comment models.
3 """ 3 """
4 from django.contrib import admin 4 from django.contrib import admin
5 from comments.models import Comment 5 from comments.models import Comment
6 from comments.models import CommentFlag 6 from comments.models import CommentFlag
7
8 import ftfy
9
7 import bio.badges 10 import bio.badges
8 11
9 12
13
10 class CommentAdmin(admin.ModelAdmin): 14 class CommentAdmin(admin.ModelAdmin):
11 fieldsets = ( 15 fieldsets = [
12 (None, 16 (None, {'fields': ['content_type', 'object_id']}),
13 {'fields': ('content_type', 'object_id', )} 17 ('Content', {'fields': ['user', 'comment']}),
14 ), 18 ('Metadata', {'fields': ['ip_address', 'is_public', 'is_removed']}),
15 ('Content', 19 ]
16 {'fields': ('user', 'comment')} 20 list_display = ['__unicode__', 'content_type', 'object_id', 'ip_address',
17 ), 21 'creation_date', 'is_public', 'not_removed']
18 ('Metadata', 22 list_filter = ['creation_date', 'is_public', 'is_removed']
19 {'fields': ('ip_address', 'is_public', 'is_removed')}
20 ),
21 )
22 list_display = ('__unicode__', 'content_type', 'object_id', 'ip_address',
23 'creation_date', 'is_public', 'not_removed')
24 list_filter = ('creation_date', 'is_public', 'is_removed')
25 date_hierarchy = 'creation_date' 23 date_hierarchy = 'creation_date'
26 ordering = ('-creation_date', ) 24 ordering = ['-creation_date']
27 search_fields = ('comment', 'user__username', 'ip_address') 25 search_fields = ['comment', 'user__username', 'ip_address']
28 raw_id_fields = ('user', 'content_type') 26 raw_id_fields = ['user', 'content_type']
27 actions = ['fix_text']
28
29 def fix_text(self, request, qs):
30 for comment in qs:
31 comment.comment = ftfy.fix_text(comment.comment)
32 comment.save()
33
34 count = len(qs)
35 msg = "1 comment" if count == 1 else "%d comments" % count
36 self.message_user(request, "Text fixed on {}".format(msg))
37
38 fix_text.short_description = "Fix text on selected comments"
29 39
30 40
31 class CommentFlagAdmin(admin.ModelAdmin): 41 class CommentFlagAdmin(admin.ModelAdmin):
32 list_display = ('__unicode__', 'flag_date', 'get_comment_url') 42 list_display = ('__unicode__', 'flag_date', 'get_comment_url')
33 actions = ('accept_flags', ) 43 actions = ('accept_flags', )