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@98
|
54 list_display = ('__unicode__', 'flag_date', 'get_post_url')
|
bgneal@204
|
55 actions = ('accept_flags', )
|
bgneal@204
|
56
|
bgneal@204
|
57 def accept_flags(self, request, qs):
|
bgneal@204
|
58 """This admin action awards a security pin to the user who reported
|
bgneal@204
|
59 the post and then deletes the flagged post object.
|
bgneal@204
|
60 """
|
bgneal@204
|
61 for flag in qs:
|
bgneal@204
|
62 bio.badges.award_badge(bio.badges.SECURITY_PIN, flag.user)
|
bgneal@204
|
63 flag.delete()
|
bgneal@204
|
64
|
bgneal@204
|
65 accept_flags.short_description = "Accept selected flagged posts"
|
bgneal@98
|
66
|
bgneal@98
|
67
|
bgneal@307
|
68 class ForumLastVisitAdmin(admin.ModelAdmin):
|
bgneal@307
|
69 raw_id_fields = ('user', 'forum')
|
bgneal@307
|
70 list_display = ('user', 'forum', 'begin_date', 'end_date')
|
bgneal@307
|
71
|
bgneal@307
|
72
|
bgneal@113
|
73 class TopicLastVisitAdmin(admin.ModelAdmin):
|
bgneal@113
|
74 raw_id_fields = ('user', 'topic')
|
bgneal@113
|
75 list_display = ('user', 'topic', 'last_visit')
|
bgneal@113
|
76
|
bgneal@113
|
77
|
bgneal@75
|
78 admin.site.register(Category, CategoryAdmin)
|
bgneal@75
|
79 admin.site.register(Forum, ForumAdmin)
|
bgneal@75
|
80 admin.site.register(Topic, TopicAdmin)
|
bgneal@75
|
81 admin.site.register(Post, PostAdmin)
|
bgneal@98
|
82 admin.site.register(FlaggedPost, FlaggedPostAdmin)
|
bgneal@307
|
83 admin.site.register(ForumLastVisit, ForumLastVisitAdmin)
|
bgneal@113
|
84 admin.site.register(TopicLastVisit, TopicLastVisitAdmin)
|