comparison messages/admin.py @ 810:4a4fa174a0ec

Private message refactor: adding ability to report PM's. See also Bitbucket issue #57.
author Brian Neal <bgneal@gmail.com>
date Sat, 06 Sep 2014 16:58:08 -0500
parents ee87ea74d46b
children
comparison
equal deleted inserted replaced
809:ab3deff7672a 810:4a4fa174a0ec
1 """ 1 """
2 This file contains the automatic admin site definitions for the Message models. 2 This file contains the automatic admin site definitions for the Message models.
3 """ 3 """
4 from django.contrib import admin 4 from django.contrib import admin
5 from django.core.urlresolvers import reverse
5 6
6 from messages.models import Message 7 from messages.models import Flag, Message, Options
7 from messages.models import Options 8 import bio.badges
8 9
9 10
10 class MessageAdmin(admin.ModelAdmin): 11 class MessageAdmin(admin.ModelAdmin):
11 list_display = ('sender', 'receiver', 'send_date', 'subject') 12 list_display = ['sender', 'receiver', 'send_date', 'subject']
12 raw_id_fields = ('sender', 'receiver') 13 raw_id_fields = ['sender', 'receiver']
13 exclude = ('html', ) 14 exclude = ['html']
14 date_hierarchy = 'send_date' 15 date_hierarchy = 'send_date'
15 list_display_links = ('subject', ) 16 list_display_links = ['subject']
16 17
18
19 class FlagAdmin(admin.ModelAdmin):
20 list_display = ['__unicode__', 'flag_date', 'message_link']
21 date_hierarchy = 'flag_date'
22 list_select_related = True
23 readonly_fields = ['message', 'flag_date', 'comments', 'message_text']
24 actions = ['accept_flags']
25
26 def message_link(self, obj):
27 return '<a href="{}">Message</a>'.format(
28 reverse('admin:messages_message_change', args=[obj.message.id]))
29 message_link.allow_tags = True
30 message_link.short_description = 'Message'
31
32 def message_text(self, obj):
33 return obj.message.html
34 message_text.allow_tags = True
35 message_text.short_description = 'Message text'
36
37 def accept_flags(self, request, qs):
38 """This admin action awards a security pin to the user who reported the
39 message and then deletes the flag object.
40
41 """
42 count = qs.count()
43 for flag in qs:
44 bio.badges.award_badge(bio.badges.SECURITY_PIN, flag.message.receiver)
45 flag.delete()
46
47 self.message_user(request,
48 "%s flag(s) acknowledged. You may want to mark users as spammers now." % count)
49
50 accept_flags.short_description = "Accept selected flags"
51
52 admin.site.register(Flag, FlagAdmin)
17 admin.site.register(Message, MessageAdmin) 53 admin.site.register(Message, MessageAdmin)
18 admin.site.register(Options) 54 admin.site.register(Options)