comparison gpp/comments/admin.py @ 204:b4305e18d3af

Resolve ticket #74. Add user badges. Some extra credit was done here: also refactored how pending news, links, and downloads are handled.
author Brian Neal <bgneal@gmail.com>
date Sat, 01 May 2010 21:53:59 +0000
parents 91a01b8b5885
children cdfa3ed59600
comparison
equal deleted inserted replaced
203:40e5903903e1 204:b4305e18d3af
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 import bio.badges
8
7 9
8 class CommentAdmin(admin.ModelAdmin): 10 class CommentAdmin(admin.ModelAdmin):
9 fieldsets = ( 11 fieldsets = (
10 (None, 12 (None,
11 {'fields': ('content_type', 'object_id', )} 13 {'fields': ('content_type', 'object_id', )}
23 date_hierarchy = 'creation_date' 25 date_hierarchy = 'creation_date'
24 ordering = ('-creation_date', ) 26 ordering = ('-creation_date', )
25 search_fields = ('comment', 'user__username', 'ip_address') 27 search_fields = ('comment', 'user__username', 'ip_address')
26 raw_id_fields = ('user', 'content_type') 28 raw_id_fields = ('user', 'content_type')
27 29
30
28 class CommentFlagAdmin(admin.ModelAdmin): 31 class CommentFlagAdmin(admin.ModelAdmin):
29 list_display = ('__unicode__', 'flag_date', 'get_comment_url') 32 list_display = ('__unicode__', 'flag_date', 'get_comment_url')
33 actions = ('accept_flags', )
34
35 def accept_flags(self, request, qs):
36 """This admin action awards a security pin to the user who reported
37 the comment and then deletes the flagged comment object.
38 """
39 for flag in qs:
40 bio.badges.award_badge(bio.badges.SECURITY_PIN, flag.user)
41 flag.delete()
42
43 accept_flags.short_description = "Accept selected comment flags"
44
30 45
31 admin.site.register(Comment, CommentAdmin) 46 admin.site.register(Comment, CommentAdmin)
32 admin.site.register(CommentFlag, CommentFlagAdmin) 47 admin.site.register(CommentFlag, CommentFlagAdmin)