annotate gpp/comments/admin.py @ 265:1ba2c6bf6eb7

Closing #98. Animated GIFs were losing their transparency and animated properties when saved as avatars. Reworked the avatar save process to only run the avatar through PIL if it is too big. This preserves the original uploaded file if it is within the desired size settings. This may still mangle big animated gifs. If this becomes a problem, then maybe look into calling the PIL Image.resize() method directly. Moved the PIL image specific functions from bio.forms to a new module: core.image for better reusability in the future.
author Brian Neal <bgneal@gmail.com>
date Fri, 24 Sep 2010 02:12:09 +0000
parents b4305e18d3af
children cdfa3ed59600
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@204 7 import bio.badges
bgneal@204 8
gremmie@1 9
gremmie@1 10 class CommentAdmin(admin.ModelAdmin):
gremmie@1 11 fieldsets = (
gremmie@1 12 (None,
gremmie@1 13 {'fields': ('content_type', 'object_id', )}
gremmie@1 14 ),
gremmie@1 15 ('Content',
gremmie@1 16 {'fields': ('user', 'comment')}
gremmie@1 17 ),
gremmie@1 18 ('Metadata',
gremmie@1 19 {'fields': ('ip_address', 'is_public', 'is_removed')}
gremmie@1 20 ),
gremmie@1 21 )
bgneal@140 22 list_display = ('__unicode__', 'content_type', 'object_id', 'ip_address',
bgneal@140 23 'creation_date', 'is_public', 'not_removed')
gremmie@1 24 list_filter = ('creation_date', 'is_public', 'is_removed')
gremmie@1 25 date_hierarchy = 'creation_date'
gremmie@1 26 ordering = ('-creation_date', )
gremmie@1 27 search_fields = ('comment', 'user__username', 'ip_address')
gremmie@1 28 raw_id_fields = ('user', 'content_type')
gremmie@1 29
bgneal@204 30
gremmie@1 31 class CommentFlagAdmin(admin.ModelAdmin):
bgneal@13 32 list_display = ('__unicode__', 'flag_date', 'get_comment_url')
bgneal@204 33 actions = ('accept_flags', )
bgneal@204 34
bgneal@204 35 def accept_flags(self, request, qs):
bgneal@204 36 """This admin action awards a security pin to the user who reported
bgneal@204 37 the comment and then deletes the flagged comment object.
bgneal@204 38 """
bgneal@204 39 for flag in qs:
bgneal@204 40 bio.badges.award_badge(bio.badges.SECURITY_PIN, flag.user)
bgneal@204 41 flag.delete()
bgneal@204 42
bgneal@204 43 accept_flags.short_description = "Accept selected comment flags"
bgneal@204 44
gremmie@1 45
gremmie@1 46 admin.site.register(Comment, CommentAdmin)
gremmie@1 47 admin.site.register(CommentFlag, CommentFlagAdmin)