annotate gpp/forums/admin.py @ 557:7247a406f92b

Merging change to requirements.txt made on production server.
author Brian Neal <bgneal@gmail.com>
date Sun, 29 Jan 2012 14:45:09 -0600
parents 9e42e6618168
children 98b373ca09f3
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@552 43 list_display = ('user', 'creation_date', 'update_date', 'user_ip', '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@552 52 def queryset(self, request):
bgneal@552 53 return Post.objects.select_related('user')
bgneal@552 54
bgneal@75 55
bgneal@98 56 class FlaggedPostAdmin(admin.ModelAdmin):
bgneal@465 57 list_display = ['__unicode__', 'flag_date', 'get_post_url']
bgneal@465 58 actions = ['accept_flags']
bgneal@465 59 raw_id_fields = ['post', 'user', ]
bgneal@204 60
bgneal@204 61 def accept_flags(self, request, qs):
bgneal@204 62 """This admin action awards a security pin to the user who reported
bgneal@204 63 the post and then deletes the flagged post object.
bgneal@204 64 """
bgneal@204 65 for flag in qs:
bgneal@204 66 bio.badges.award_badge(bio.badges.SECURITY_PIN, flag.user)
bgneal@204 67 flag.delete()
bgneal@204 68
bgneal@204 69 accept_flags.short_description = "Accept selected flagged posts"
bgneal@98 70
bgneal@98 71
bgneal@307 72 class ForumLastVisitAdmin(admin.ModelAdmin):
bgneal@307 73 raw_id_fields = ('user', 'forum')
bgneal@307 74 list_display = ('user', 'forum', 'begin_date', 'end_date')
bgneal@307 75
bgneal@307 76
bgneal@113 77 class TopicLastVisitAdmin(admin.ModelAdmin):
bgneal@113 78 raw_id_fields = ('user', 'topic')
bgneal@113 79 list_display = ('user', 'topic', 'last_visit')
bgneal@113 80
bgneal@113 81
bgneal@75 82 admin.site.register(Category, CategoryAdmin)
bgneal@75 83 admin.site.register(Forum, ForumAdmin)
bgneal@75 84 admin.site.register(Topic, TopicAdmin)
bgneal@75 85 admin.site.register(Post, PostAdmin)
bgneal@98 86 admin.site.register(FlaggedPost, FlaggedPostAdmin)
bgneal@307 87 admin.site.register(ForumLastVisit, ForumLastVisitAdmin)
bgneal@113 88 admin.site.register(TopicLastVisit, TopicLastVisitAdmin)