bgneal@75: """ bgneal@75: This file contains the admin definitions for the forums application. bgneal@75: """ bgneal@75: from django.contrib import admin bgneal@75: bgneal@75: from forums.models import Category bgneal@75: from forums.models import Forum bgneal@75: from forums.models import Topic bgneal@75: from forums.models import Post bgneal@98: from forums.models import FlaggedPost bgneal@307: from forums.models import ForumLastVisit bgneal@113: from forums.models import TopicLastVisit bgneal@562: from forums.signals import (notify_new_topic, notify_updated_topic, bgneal@562: notify_new_post, notify_updated_post) bgneal@562: bgneal@204: import bio.badges bgneal@75: bgneal@75: bgneal@75: class CategoryAdmin(admin.ModelAdmin): bgneal@75: list_display = ('name', 'position', ) bgneal@206: list_editable = ('position', ) bgneal@81: prepopulated_fields = { 'slug': ('name', ) } bgneal@81: save_on_top = True bgneal@75: bgneal@75: bgneal@75: class ForumAdmin(admin.ModelAdmin): bgneal@75: list_display = ('name', 'category', 'position', 'topic_count', 'post_count') bgneal@206: list_editable = ('position', ) bgneal@75: prepopulated_fields = { 'slug': ('name', ) } bgneal@75: raw_id_fields = ('last_post', ) bgneal@206: ordering = ('category', ) bgneal@81: save_on_top = True bgneal@81: bgneal@75: bgneal@75: class TopicAdmin(admin.ModelAdmin): bgneal@102: list_display = ('name', 'forum', 'creation_date', 'update_date', 'user', 'sticky', 'locked', bgneal@75: 'post_count') bgneal@232: raw_id_fields = ('user', 'last_post', 'subscribers', 'bookmarkers') bgneal@75: search_fields = ('name', ) bgneal@75: date_hierarchy = 'creation_date' bgneal@75: list_filter = ('creation_date', 'update_date', ) bgneal@81: save_on_top = True bgneal@75: bgneal@562: # override save_model() to update the search index bgneal@562: def save_model(self, request, obj, form, change): bgneal@562: obj.save() bgneal@562: bgneal@562: if change: bgneal@562: notify_updated_topic(obj) bgneal@562: else: bgneal@562: notify_new_topic(obj) bgneal@562: bgneal@75: bgneal@75: class PostAdmin(admin.ModelAdmin): bgneal@552: list_display = ('user', 'creation_date', 'update_date', 'user_ip', 'summary') bgneal@75: raw_id_fields = ('topic', 'user', ) bgneal@75: exclude = ('html', ) bgneal@75: search_fields = ('body', ) bgneal@75: date_hierarchy = 'creation_date' bgneal@75: list_filter = ('creation_date', 'update_date', ) bgneal@97: ordering = ('-creation_date', ) bgneal@81: save_on_top = True bgneal@75: bgneal@552: def queryset(self, request): bgneal@552: return Post.objects.select_related('user') bgneal@552: bgneal@562: # override save_model() to update the search index bgneal@562: def save_model(self, request, obj, form, change): bgneal@562: obj.save() bgneal@562: bgneal@562: if change: bgneal@562: notify_updated_post(obj) bgneal@562: else: bgneal@562: notify_new_post(obj) bgneal@562: bgneal@75: bgneal@98: class FlaggedPostAdmin(admin.ModelAdmin): bgneal@465: list_display = ['__unicode__', 'flag_date', 'get_post_url'] bgneal@465: actions = ['accept_flags'] bgneal@465: raw_id_fields = ['post', 'user', ] bgneal@204: bgneal@204: def accept_flags(self, request, qs): bgneal@204: """This admin action awards a security pin to the user who reported bgneal@204: the post and then deletes the flagged post object. bgneal@204: """ bgneal@204: for flag in qs: bgneal@204: bio.badges.award_badge(bio.badges.SECURITY_PIN, flag.user) bgneal@204: flag.delete() bgneal@204: bgneal@204: accept_flags.short_description = "Accept selected flagged posts" bgneal@98: bgneal@98: bgneal@307: class ForumLastVisitAdmin(admin.ModelAdmin): bgneal@307: raw_id_fields = ('user', 'forum') bgneal@307: list_display = ('user', 'forum', 'begin_date', 'end_date') bgneal@307: bgneal@307: bgneal@113: class TopicLastVisitAdmin(admin.ModelAdmin): bgneal@113: raw_id_fields = ('user', 'topic') bgneal@113: list_display = ('user', 'topic', 'last_visit') bgneal@113: bgneal@113: bgneal@75: admin.site.register(Category, CategoryAdmin) bgneal@75: admin.site.register(Forum, ForumAdmin) bgneal@75: admin.site.register(Topic, TopicAdmin) bgneal@75: admin.site.register(Post, PostAdmin) bgneal@98: admin.site.register(FlaggedPost, FlaggedPostAdmin) bgneal@307: admin.site.register(ForumLastVisit, ForumLastVisitAdmin) bgneal@113: admin.site.register(TopicLastVisit, TopicLastVisitAdmin)