annotate comments/admin.py @ 1101:999b32c63cae

Made main menu aligned to right. Since expanded seems broken...
author Brian Neal <bgneal@gmail.com>
date Wed, 06 Jul 2016 19:46:20 -0500
parents be5b37719059
children
rev   line source
gremmie@1 1 """
gremmie@1 2 This file contains the automatic admin site definitions for the comment models.
gremmie@1 3 """
gremmie@1 4 from django.contrib import admin
gremmie@1 5 from comments.models import Comment
gremmie@1 6 from comments.models import CommentFlag
bgneal@671 7
bgneal@671 8 import ftfy
bgneal@671 9
bgneal@204 10 import bio.badges
bgneal@204 11
gremmie@1 12
bgneal@671 13
gremmie@1 14 class CommentAdmin(admin.ModelAdmin):
bgneal@671 15 fieldsets = [
bgneal@671 16 (None, {'fields': ['content_type', 'object_id']}),
bgneal@671 17 ('Content', {'fields': ['user', 'comment']}),
bgneal@671 18 ('Metadata', {'fields': ['ip_address', 'is_public', 'is_removed']}),
bgneal@671 19 ]
bgneal@671 20 list_display = ['__unicode__', 'content_type', 'object_id', 'ip_address',
bgneal@671 21 'creation_date', 'is_public', 'not_removed']
bgneal@671 22 list_filter = ['creation_date', 'is_public', 'is_removed']
gremmie@1 23 date_hierarchy = 'creation_date'
bgneal@671 24 ordering = ['-creation_date']
bgneal@671 25 search_fields = ['comment', 'user__username', 'ip_address']
bgneal@671 26 raw_id_fields = ['user', 'content_type']
bgneal@671 27 actions = ['fix_text']
bgneal@671 28
bgneal@671 29 def fix_text(self, request, qs):
bgneal@671 30 for comment in qs:
bgneal@671 31 comment.comment = ftfy.fix_text(comment.comment)
bgneal@671 32 comment.save()
bgneal@671 33
bgneal@671 34 count = len(qs)
bgneal@671 35 msg = "1 comment" if count == 1 else "%d comments" % count
bgneal@671 36 self.message_user(request, "Text fixed on {}".format(msg))
bgneal@671 37
bgneal@671 38 fix_text.short_description = "Fix text on selected comments"
gremmie@1 39
bgneal@204 40
gremmie@1 41 class CommentFlagAdmin(admin.ModelAdmin):
bgneal@13 42 list_display = ('__unicode__', 'flag_date', 'get_comment_url')
bgneal@204 43 actions = ('accept_flags', )
bgneal@365 44 raw_id_fields = ('user', 'comment')
bgneal@204 45
bgneal@204 46 def accept_flags(self, request, qs):
bgneal@204 47 """This admin action awards a security pin to the user who reported
bgneal@204 48 the comment and then deletes the flagged comment object.
bgneal@204 49 """
bgneal@204 50 for flag in qs:
bgneal@204 51 bio.badges.award_badge(bio.badges.SECURITY_PIN, flag.user)
bgneal@204 52 flag.delete()
bgneal@204 53
bgneal@204 54 accept_flags.short_description = "Accept selected comment flags"
bgneal@204 55
gremmie@1 56
gremmie@1 57 admin.site.register(Comment, CommentAdmin)
gremmie@1 58 admin.site.register(CommentFlag, CommentFlagAdmin)