gremmie@1: """ gremmie@1: This file contains the automatic admin site definitions for the Message models. gremmie@1: """ bgneal@299: from django.contrib import admin bgneal@810: from django.core.urlresolvers import reverse gremmie@1: bgneal@810: from messages.models import Flag, Message, Options bgneal@810: import bio.badges gremmie@1: bgneal@299: bgneal@299: class MessageAdmin(admin.ModelAdmin): bgneal@810: list_display = ['sender', 'receiver', 'send_date', 'subject'] bgneal@810: raw_id_fields = ['sender', 'receiver'] bgneal@810: exclude = ['html'] bgneal@299: date_hierarchy = 'send_date' bgneal@810: list_display_links = ['subject'] bgneal@299: bgneal@810: bgneal@810: class FlagAdmin(admin.ModelAdmin): bgneal@810: list_display = ['__unicode__', 'flag_date', 'message_link'] bgneal@810: date_hierarchy = 'flag_date' bgneal@810: list_select_related = True bgneal@810: readonly_fields = ['message', 'flag_date', 'comments', 'message_text'] bgneal@810: actions = ['accept_flags'] bgneal@810: bgneal@810: def message_link(self, obj): bgneal@810: return 'Message'.format( bgneal@810: reverse('admin:messages_message_change', args=[obj.message.id])) bgneal@810: message_link.allow_tags = True bgneal@810: message_link.short_description = 'Message' bgneal@810: bgneal@810: def message_text(self, obj): bgneal@810: return obj.message.html bgneal@810: message_text.allow_tags = True bgneal@810: message_text.short_description = 'Message text' bgneal@810: bgneal@810: def accept_flags(self, request, qs): bgneal@810: """This admin action awards a security pin to the user who reported the bgneal@810: message and then deletes the flag object. bgneal@810: bgneal@810: """ bgneal@810: count = qs.count() bgneal@810: for flag in qs: bgneal@810: bio.badges.award_badge(bio.badges.SECURITY_PIN, flag.message.receiver) bgneal@810: flag.delete() bgneal@810: bgneal@810: self.message_user(request, bgneal@810: "%s flag(s) acknowledged. You may want to mark users as spammers now." % count) bgneal@810: bgneal@810: accept_flags.short_description = "Accept selected flags" bgneal@810: bgneal@810: admin.site.register(Flag, FlagAdmin) bgneal@299: admin.site.register(Message, MessageAdmin) gremmie@1: admin.site.register(Options)