annotate gpp/forums/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 500e5875a306
children 272d3a8c98e8
rev   line source
bgneal@75 1 """
bgneal@75 2 This file contains the admin definitions for the forums application.
bgneal@75 3 """
bgneal@75 4 from django.contrib import admin
bgneal@75 5
bgneal@75 6 from forums.models import Category
bgneal@75 7 from forums.models import Forum
bgneal@75 8 from forums.models import Topic
bgneal@75 9 from forums.models import Post
bgneal@98 10 from forums.models import FlaggedPost
bgneal@113 11 from forums.models import TopicLastVisit
bgneal@204 12 import bio.badges
bgneal@75 13
bgneal@75 14
bgneal@75 15 class CategoryAdmin(admin.ModelAdmin):
bgneal@75 16 list_display = ('name', 'position', )
bgneal@81 17 prepopulated_fields = { 'slug': ('name', ) }
bgneal@81 18 save_on_top = True
bgneal@75 19
bgneal@75 20
bgneal@75 21 class ForumAdmin(admin.ModelAdmin):
bgneal@75 22 list_display = ('name', 'category', 'position', 'topic_count', 'post_count')
bgneal@75 23 prepopulated_fields = { 'slug': ('name', ) }
bgneal@75 24 raw_id_fields = ('last_post', )
bgneal@81 25 save_on_top = True
bgneal@81 26
bgneal@75 27
bgneal@75 28 class TopicAdmin(admin.ModelAdmin):
bgneal@102 29 list_display = ('name', 'forum', 'creation_date', 'update_date', 'user', 'sticky', 'locked',
bgneal@75 30 'post_count')
bgneal@181 31 raw_id_fields = ('user', 'last_post', 'subscribers')
bgneal@75 32 search_fields = ('name', )
bgneal@75 33 date_hierarchy = 'creation_date'
bgneal@75 34 list_filter = ('creation_date', 'update_date', )
bgneal@81 35 save_on_top = True
bgneal@75 36
bgneal@75 37
bgneal@75 38 class PostAdmin(admin.ModelAdmin):
bgneal@75 39 list_display = ('topic', 'user', 'creation_date', 'update_date', 'summary')
bgneal@75 40 raw_id_fields = ('topic', 'user', )
bgneal@75 41 exclude = ('html', )
bgneal@75 42 search_fields = ('body', )
bgneal@75 43 date_hierarchy = 'creation_date'
bgneal@75 44 list_filter = ('creation_date', 'update_date', )
bgneal@97 45 ordering = ('-creation_date', )
bgneal@81 46 save_on_top = True
bgneal@75 47
bgneal@75 48
bgneal@98 49 class FlaggedPostAdmin(admin.ModelAdmin):
bgneal@98 50 list_display = ('__unicode__', 'flag_date', 'get_post_url')
bgneal@204 51 actions = ('accept_flags', )
bgneal@204 52
bgneal@204 53 def accept_flags(self, request, qs):
bgneal@204 54 """This admin action awards a security pin to the user who reported
bgneal@204 55 the post and then deletes the flagged post object.
bgneal@204 56 """
bgneal@204 57 for flag in qs:
bgneal@204 58 bio.badges.award_badge(bio.badges.SECURITY_PIN, flag.user)
bgneal@204 59 flag.delete()
bgneal@204 60
bgneal@204 61 accept_flags.short_description = "Accept selected flagged posts"
bgneal@98 62
bgneal@98 63
bgneal@113 64 class TopicLastVisitAdmin(admin.ModelAdmin):
bgneal@113 65 raw_id_fields = ('user', 'topic')
bgneal@113 66 list_display = ('user', 'topic', 'last_visit')
bgneal@113 67
bgneal@113 68
bgneal@75 69 admin.site.register(Category, CategoryAdmin)
bgneal@75 70 admin.site.register(Forum, ForumAdmin)
bgneal@75 71 admin.site.register(Topic, TopicAdmin)
bgneal@75 72 admin.site.register(Post, PostAdmin)
bgneal@98 73 admin.site.register(FlaggedPost, FlaggedPostAdmin)
bgneal@113 74 admin.site.register(TopicLastVisit, TopicLastVisitAdmin)