Mercurial > public > sg101
comparison forums/admin.py @ 581:ee87ea74d46b
For Django 1.4, rearranged project structure for new manage.py.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 05 May 2012 17:10:48 -0500 |
parents | gpp/forums/admin.py@98b373ca09f3 |
children | 3e1905e523be |
comparison
equal
deleted
inserted
replaced
580:c525f3e0b5d0 | 581:ee87ea74d46b |
---|---|
1 """ | |
2 This file contains the admin definitions for the forums application. | |
3 """ | |
4 from django.contrib import admin | |
5 | |
6 from forums.models import Category | |
7 from forums.models import Forum | |
8 from forums.models import Topic | |
9 from forums.models import Post | |
10 from forums.models import FlaggedPost | |
11 from forums.models import ForumLastVisit | |
12 from forums.models import TopicLastVisit | |
13 from forums.signals import (notify_new_topic, notify_updated_topic, | |
14 notify_new_post, notify_updated_post) | |
15 | |
16 import bio.badges | |
17 | |
18 | |
19 class CategoryAdmin(admin.ModelAdmin): | |
20 list_display = ('name', 'position', ) | |
21 list_editable = ('position', ) | |
22 prepopulated_fields = { 'slug': ('name', ) } | |
23 save_on_top = True | |
24 | |
25 | |
26 class ForumAdmin(admin.ModelAdmin): | |
27 list_display = ('name', 'category', 'position', 'topic_count', 'post_count') | |
28 list_editable = ('position', ) | |
29 prepopulated_fields = { 'slug': ('name', ) } | |
30 raw_id_fields = ('last_post', ) | |
31 ordering = ('category', ) | |
32 save_on_top = True | |
33 | |
34 | |
35 class TopicAdmin(admin.ModelAdmin): | |
36 list_display = ('name', 'forum', 'creation_date', 'update_date', 'user', 'sticky', 'locked', | |
37 'post_count') | |
38 raw_id_fields = ('user', 'last_post', 'subscribers', 'bookmarkers') | |
39 search_fields = ('name', ) | |
40 date_hierarchy = 'creation_date' | |
41 list_filter = ('creation_date', 'update_date', ) | |
42 save_on_top = True | |
43 | |
44 # override save_model() to update the search index | |
45 def save_model(self, request, obj, form, change): | |
46 obj.save() | |
47 | |
48 if change: | |
49 notify_updated_topic(obj) | |
50 else: | |
51 notify_new_topic(obj) | |
52 | |
53 | |
54 class PostAdmin(admin.ModelAdmin): | |
55 list_display = ('user', 'creation_date', 'update_date', 'user_ip', 'summary') | |
56 raw_id_fields = ('topic', 'user', ) | |
57 exclude = ('html', ) | |
58 search_fields = ('body', ) | |
59 date_hierarchy = 'creation_date' | |
60 list_filter = ('creation_date', 'update_date', ) | |
61 ordering = ('-creation_date', ) | |
62 save_on_top = True | |
63 | |
64 def queryset(self, request): | |
65 return Post.objects.select_related('user') | |
66 | |
67 # override save_model() to update the search index | |
68 def save_model(self, request, obj, form, change): | |
69 obj.save() | |
70 | |
71 if change: | |
72 notify_updated_post(obj) | |
73 else: | |
74 notify_new_post(obj) | |
75 | |
76 | |
77 class FlaggedPostAdmin(admin.ModelAdmin): | |
78 list_display = ['__unicode__', 'flag_date', 'get_post_url'] | |
79 actions = ['accept_flags'] | |
80 raw_id_fields = ['post', 'user', ] | |
81 | |
82 def accept_flags(self, request, qs): | |
83 """This admin action awards a security pin to the user who reported | |
84 the post and then deletes the flagged post object. | |
85 """ | |
86 for flag in qs: | |
87 bio.badges.award_badge(bio.badges.SECURITY_PIN, flag.user) | |
88 flag.delete() | |
89 | |
90 accept_flags.short_description = "Accept selected flagged posts" | |
91 | |
92 | |
93 class ForumLastVisitAdmin(admin.ModelAdmin): | |
94 raw_id_fields = ('user', 'forum') | |
95 list_display = ('user', 'forum', 'begin_date', 'end_date') | |
96 | |
97 | |
98 class TopicLastVisitAdmin(admin.ModelAdmin): | |
99 raw_id_fields = ('user', 'topic') | |
100 list_display = ('user', 'topic', 'last_visit') | |
101 | |
102 | |
103 admin.site.register(Category, CategoryAdmin) | |
104 admin.site.register(Forum, ForumAdmin) | |
105 admin.site.register(Topic, TopicAdmin) | |
106 admin.site.register(Post, PostAdmin) | |
107 admin.site.register(FlaggedPost, FlaggedPostAdmin) | |
108 admin.site.register(ForumLastVisit, ForumLastVisitAdmin) | |
109 admin.site.register(TopicLastVisit, TopicLastVisitAdmin) |