annotate comments/admin.py @ 629:f4c043cf55ac

Wiki integration. Requests don't always have sessions. In particular this occurs when a request is made without a trailing slash. The Common middleware redirects when this happens, and the middleware process_request() processing stops before a session can get added. So just set an attribute on the request object for each operation. This seemed weird to me at first, but there are plenty of examples of this in the Django code base already.
author Brian Neal <bgneal@gmail.com>
date Tue, 13 Nov 2012 13:50:06 -0600
parents ee87ea74d46b
children be5b37719059
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)