Mercurial > public > sg101
comparison comments/admin.py @ 581:ee87ea74d46b
For Django 1.4, rearranged project structure for new manage.py.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 05 May 2012 17:10:48 -0500 |
parents | gpp/comments/admin.py@cdfa3ed59600 |
children | be5b37719059 |
comparison
equal
deleted
inserted
replaced
580:c525f3e0b5d0 | 581:ee87ea74d46b |
---|---|
1 """ | |
2 This file contains the automatic admin site definitions for the comment models. | |
3 """ | |
4 from django.contrib import admin | |
5 from comments.models import Comment | |
6 from comments.models import CommentFlag | |
7 import bio.badges | |
8 | |
9 | |
10 class CommentAdmin(admin.ModelAdmin): | |
11 fieldsets = ( | |
12 (None, | |
13 {'fields': ('content_type', 'object_id', )} | |
14 ), | |
15 ('Content', | |
16 {'fields': ('user', 'comment')} | |
17 ), | |
18 ('Metadata', | |
19 {'fields': ('ip_address', 'is_public', 'is_removed')} | |
20 ), | |
21 ) | |
22 list_display = ('__unicode__', 'content_type', 'object_id', 'ip_address', | |
23 'creation_date', 'is_public', 'not_removed') | |
24 list_filter = ('creation_date', 'is_public', 'is_removed') | |
25 date_hierarchy = 'creation_date' | |
26 ordering = ('-creation_date', ) | |
27 search_fields = ('comment', 'user__username', 'ip_address') | |
28 raw_id_fields = ('user', 'content_type') | |
29 | |
30 | |
31 class CommentFlagAdmin(admin.ModelAdmin): | |
32 list_display = ('__unicode__', 'flag_date', 'get_comment_url') | |
33 actions = ('accept_flags', ) | |
34 raw_id_fields = ('user', 'comment') | |
35 | |
36 def accept_flags(self, request, qs): | |
37 """This admin action awards a security pin to the user who reported | |
38 the comment and then deletes the flagged comment object. | |
39 """ | |
40 for flag in qs: | |
41 bio.badges.award_badge(bio.badges.SECURITY_PIN, flag.user) | |
42 flag.delete() | |
43 | |
44 accept_flags.short_description = "Accept selected comment flags" | |
45 | |
46 | |
47 admin.site.register(Comment, CommentAdmin) | |
48 admin.site.register(CommentFlag, CommentFlagAdmin) |