annotate gpp/comments/admin.py @ 479:32cec6cd8808

Refactor RateLimiter so that if Redis is not running, everything still runs normally (minus the rate limiting protection). My assumption that creating a Redis connection would throw an exception if Redis wasn't running was wrong. The exceptions actually occur when you issue a command. This is for #224.
author Brian Neal <bgneal@gmail.com>
date Sun, 25 Sep 2011 00:49:05 +0000
parents cdfa3ed59600
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@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@365 34 raw_id_fields = ('user', 'comment')
bgneal@204 35
bgneal@204 36 def accept_flags(self, request, qs):
bgneal@204 37 """This admin action awards a security pin to the user who reported
bgneal@204 38 the comment and then deletes the flagged comment object.
bgneal@204 39 """
bgneal@204 40 for flag in qs:
bgneal@204 41 bio.badges.award_badge(bio.badges.SECURITY_PIN, flag.user)
bgneal@204 42 flag.delete()
bgneal@204 43
bgneal@204 44 accept_flags.short_description = "Accept selected comment flags"
bgneal@204 45
gremmie@1 46
gremmie@1 47 admin.site.register(Comment, CommentAdmin)
gremmie@1 48 admin.site.register(CommentFlag, CommentFlagAdmin)