annotate gpp/forums/admin.py @ 213:65016249bf35

See #31; undid attempts to clear template tag caching when saving news and bulletins, as we don't know the cache key (it is mangled).
author Brian Neal <bgneal@gmail.com>
date Mon, 10 May 2010 02:58:19 +0000
parents 272d3a8c98e8
children a46788862737
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@206 17 list_editable = ('position', )
bgneal@81 18 prepopulated_fields = { 'slug': ('name', ) }
bgneal@81 19 save_on_top = True
bgneal@75 20
bgneal@75 21
bgneal@75 22 class ForumAdmin(admin.ModelAdmin):
bgneal@75 23 list_display = ('name', 'category', 'position', 'topic_count', 'post_count')
bgneal@206 24 list_editable = ('position', )
bgneal@75 25 prepopulated_fields = { 'slug': ('name', ) }
bgneal@75 26 raw_id_fields = ('last_post', )
bgneal@206 27 ordering = ('category', )
bgneal@81 28 save_on_top = True
bgneal@81 29
bgneal@75 30
bgneal@75 31 class TopicAdmin(admin.ModelAdmin):
bgneal@102 32 list_display = ('name', 'forum', 'creation_date', 'update_date', 'user', 'sticky', 'locked',
bgneal@75 33 'post_count')
bgneal@181 34 raw_id_fields = ('user', 'last_post', 'subscribers')
bgneal@75 35 search_fields = ('name', )
bgneal@75 36 date_hierarchy = 'creation_date'
bgneal@75 37 list_filter = ('creation_date', 'update_date', )
bgneal@81 38 save_on_top = True
bgneal@75 39
bgneal@75 40
bgneal@75 41 class PostAdmin(admin.ModelAdmin):
bgneal@75 42 list_display = ('topic', 'user', 'creation_date', 'update_date', 'summary')
bgneal@75 43 raw_id_fields = ('topic', 'user', )
bgneal@75 44 exclude = ('html', )
bgneal@75 45 search_fields = ('body', )
bgneal@75 46 date_hierarchy = 'creation_date'
bgneal@75 47 list_filter = ('creation_date', 'update_date', )
bgneal@97 48 ordering = ('-creation_date', )
bgneal@81 49 save_on_top = True
bgneal@75 50
bgneal@75 51
bgneal@98 52 class FlaggedPostAdmin(admin.ModelAdmin):
bgneal@98 53 list_display = ('__unicode__', 'flag_date', 'get_post_url')
bgneal@204 54 actions = ('accept_flags', )
bgneal@204 55
bgneal@204 56 def accept_flags(self, request, qs):
bgneal@204 57 """This admin action awards a security pin to the user who reported
bgneal@204 58 the post and then deletes the flagged post object.
bgneal@204 59 """
bgneal@204 60 for flag in qs:
bgneal@204 61 bio.badges.award_badge(bio.badges.SECURITY_PIN, flag.user)
bgneal@204 62 flag.delete()
bgneal@204 63
bgneal@204 64 accept_flags.short_description = "Accept selected flagged posts"
bgneal@98 65
bgneal@98 66
bgneal@113 67 class TopicLastVisitAdmin(admin.ModelAdmin):
bgneal@113 68 raw_id_fields = ('user', 'topic')
bgneal@113 69 list_display = ('user', 'topic', 'last_visit')
bgneal@113 70
bgneal@113 71
bgneal@75 72 admin.site.register(Category, CategoryAdmin)
bgneal@75 73 admin.site.register(Forum, ForumAdmin)
bgneal@75 74 admin.site.register(Topic, TopicAdmin)
bgneal@75 75 admin.site.register(Post, PostAdmin)
bgneal@98 76 admin.site.register(FlaggedPost, FlaggedPostAdmin)
bgneal@113 77 admin.site.register(TopicLastVisit, TopicLastVisitAdmin)