annotate gpp/forums/admin.py @ 533:387d46abcb95

Updated to Haystack 1.2.6. Got the latest Haystack, xapian backend, and queued_search from PyPi. This is for ticket #215.
author Brian Neal <bgneal@gmail.com>
date Mon, 26 Dec 2011 23:05:29 +0000
parents 79d454ff2de0
children 9e42e6618168
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@307 11 from forums.models import ForumLastVisit
bgneal@113 12 from forums.models import TopicLastVisit
bgneal@204 13 import bio.badges
bgneal@75 14
bgneal@75 15
bgneal@75 16 class CategoryAdmin(admin.ModelAdmin):
bgneal@75 17 list_display = ('name', 'position', )
bgneal@206 18 list_editable = ('position', )
bgneal@81 19 prepopulated_fields = { 'slug': ('name', ) }
bgneal@81 20 save_on_top = True
bgneal@75 21
bgneal@75 22
bgneal@75 23 class ForumAdmin(admin.ModelAdmin):
bgneal@75 24 list_display = ('name', 'category', 'position', 'topic_count', 'post_count')
bgneal@206 25 list_editable = ('position', )
bgneal@75 26 prepopulated_fields = { 'slug': ('name', ) }
bgneal@75 27 raw_id_fields = ('last_post', )
bgneal@206 28 ordering = ('category', )
bgneal@81 29 save_on_top = True
bgneal@81 30
bgneal@75 31
bgneal@75 32 class TopicAdmin(admin.ModelAdmin):
bgneal@102 33 list_display = ('name', 'forum', 'creation_date', 'update_date', 'user', 'sticky', 'locked',
bgneal@75 34 'post_count')
bgneal@232 35 raw_id_fields = ('user', 'last_post', 'subscribers', 'bookmarkers')
bgneal@75 36 search_fields = ('name', )
bgneal@75 37 date_hierarchy = 'creation_date'
bgneal@75 38 list_filter = ('creation_date', 'update_date', )
bgneal@81 39 save_on_top = True
bgneal@75 40
bgneal@75 41
bgneal@75 42 class PostAdmin(admin.ModelAdmin):
bgneal@75 43 list_display = ('topic', 'user', 'creation_date', 'update_date', 'summary')
bgneal@75 44 raw_id_fields = ('topic', 'user', )
bgneal@75 45 exclude = ('html', )
bgneal@75 46 search_fields = ('body', )
bgneal@75 47 date_hierarchy = 'creation_date'
bgneal@75 48 list_filter = ('creation_date', 'update_date', )
bgneal@97 49 ordering = ('-creation_date', )
bgneal@81 50 save_on_top = True
bgneal@75 51
bgneal@75 52
bgneal@98 53 class FlaggedPostAdmin(admin.ModelAdmin):
bgneal@465 54 list_display = ['__unicode__', 'flag_date', 'get_post_url']
bgneal@465 55 actions = ['accept_flags']
bgneal@465 56 raw_id_fields = ['post', 'user', ]
bgneal@204 57
bgneal@204 58 def accept_flags(self, request, qs):
bgneal@204 59 """This admin action awards a security pin to the user who reported
bgneal@204 60 the post and then deletes the flagged post object.
bgneal@204 61 """
bgneal@204 62 for flag in qs:
bgneal@204 63 bio.badges.award_badge(bio.badges.SECURITY_PIN, flag.user)
bgneal@204 64 flag.delete()
bgneal@204 65
bgneal@204 66 accept_flags.short_description = "Accept selected flagged posts"
bgneal@98 67
bgneal@98 68
bgneal@307 69 class ForumLastVisitAdmin(admin.ModelAdmin):
bgneal@307 70 raw_id_fields = ('user', 'forum')
bgneal@307 71 list_display = ('user', 'forum', 'begin_date', 'end_date')
bgneal@307 72
bgneal@307 73
bgneal@113 74 class TopicLastVisitAdmin(admin.ModelAdmin):
bgneal@113 75 raw_id_fields = ('user', 'topic')
bgneal@113 76 list_display = ('user', 'topic', 'last_visit')
bgneal@113 77
bgneal@113 78
bgneal@75 79 admin.site.register(Category, CategoryAdmin)
bgneal@75 80 admin.site.register(Forum, ForumAdmin)
bgneal@75 81 admin.site.register(Topic, TopicAdmin)
bgneal@75 82 admin.site.register(Post, PostAdmin)
bgneal@98 83 admin.site.register(FlaggedPost, FlaggedPostAdmin)
bgneal@307 84 admin.site.register(ForumLastVisit, ForumLastVisitAdmin)
bgneal@113 85 admin.site.register(TopicLastVisit, TopicLastVisitAdmin)