Mercurial > public > sg101
comparison news/admin.py @ 1001:c6c3ba5cf6eb
V2 news stories use forums for comments.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 26 Nov 2015 00:27:42 -0600 |
parents | 8386a8ebcbc7 |
children | 9fc12bbc8c81 |
comparison
equal
deleted
inserted
replaced
1000:abd4c02aefdb | 1001:c6c3ba5cf6eb |
---|---|
2 This file contains the automatic admin site definitions for the News models. | 2 This file contains the automatic admin site definitions for the News models. |
3 """ | 3 """ |
4 from django.contrib import admin | 4 from django.contrib import admin |
5 from django.conf import settings | 5 from django.conf import settings |
6 | 6 |
7 from forums.tools import create_topic | |
7 from news.models import PendingStory | 8 from news.models import PendingStory |
8 from news.models import Story | 9 from news.models import Story |
9 from news.models import Category | 10 from news.models import Category |
10 | 11 |
11 import ftfy | 12 import ftfy |
12 | 13 |
13 | 14 |
15 COMMENT_THREAD_BODY = ("This topic was automatically created to discuss the " | |
16 "news story [{title}]({url}).") | |
17 | |
18 | |
14 class CategoryAdmin(admin.ModelAdmin): | 19 class CategoryAdmin(admin.ModelAdmin): |
15 prepopulated_fields = {'slug': ("title", )} | 20 prepopulated_fields = {'slug': ("title", )} |
16 list_display = ['title', 'slug'] | 21 list_display = ['title', 'slug', 'forum_slug'] |
22 list_editable = ['forum_slug'] | |
17 | 23 |
18 | 24 |
19 class PendingStoryAdmin(admin.ModelAdmin): | 25 class PendingStoryAdmin(admin.ModelAdmin): |
20 list_display = ['title', 'date_submitted', 'submitter'] | 26 list_display = ['title', 'date_submitted', 'submitter'] |
21 list_filter = ['date_submitted'] | 27 list_filter = ['date_submitted'] |
22 search_fields = ['title', 'short_text', 'long_text'] | 28 search_fields = ['title', 'short_text', 'long_text'] |
23 date_hierarchy = 'date_submitted' | 29 date_hierarchy = 'date_submitted' |
24 actions = ['approve_story'] | 30 actions = ['approve_stories'] |
25 readonly_fields = ['update_date', 'version'] | 31 readonly_fields = ['update_date', 'version'] |
26 raw_id_fields = ['submitter'] | 32 raw_id_fields = ['submitter'] |
27 | 33 |
28 fieldsets = [ | 34 fieldsets = [ |
29 (None, { | 35 (None, { |
46 'fields': ['update_date', 'version'], | 52 'fields': ['update_date', 'version'], |
47 'classes': ['collapse'], | 53 'classes': ['collapse'], |
48 }), | 54 }), |
49 ] | 55 ] |
50 | 56 |
51 def approve_story(self, request, qs): | 57 def approve_stories(self, request, qs): |
52 for pending_story in qs: | 58 for pending_story in qs: |
53 story = Story( | 59 self._approve_story(pending_story) |
54 title=pending_story.title, | |
55 submitter=pending_story.submitter, | |
56 category=pending_story.category, | |
57 short_text=pending_story.short_text, | |
58 long_text=pending_story.long_text, | |
59 date_submitted=pending_story.date_submitted, | |
60 allow_comments=pending_story.allow_comments, | |
61 tags=pending_story.tags, | |
62 front_page_expiration=pending_story.front_page_expiration, | |
63 priority=pending_story.priority, | |
64 meta_description=pending_story.meta_description, | |
65 short_markup=pending_story.short_markup, | |
66 long_markup=pending_story.long_markup, | |
67 admin_content=pending_story.admin_content) | |
68 story.save() | |
69 pending_story.delete() | |
70 | 60 |
71 count = len(qs) | 61 count = len(qs) |
72 msg = "1 story" if count == 1 else "%d stories" % count | 62 msg = "1 story" if count == 1 else "%d stories" % count |
73 self.message_user(request, "%s approved." % msg) | 63 self.message_user(request, "%s approved." % msg) |
74 | 64 |
75 approve_story.short_description = "Approve selected pending stories" | 65 approve_stories.short_description = "Approve selected pending stories" |
66 | |
67 def _approve_story(self, pending_story): | |
68 story = Story( | |
69 title=pending_story.title, | |
70 submitter=pending_story.submitter, | |
71 category=pending_story.category, | |
72 short_text=pending_story.short_text, | |
73 long_text=pending_story.long_text, | |
74 date_submitted=pending_story.date_submitted, | |
75 allow_comments=pending_story.allow_comments, | |
76 tags=pending_story.tags, | |
77 front_page_expiration=pending_story.front_page_expiration, | |
78 priority=pending_story.priority, | |
79 meta_description=pending_story.meta_description, | |
80 short_markup=pending_story.short_markup, | |
81 long_markup=pending_story.long_markup, | |
82 admin_content=pending_story.admin_content) | |
83 story.save() | |
84 pending_story.delete() | |
85 | |
86 # Create comment thread if configured to do so. | |
87 forum_slug = story.category.forum_slug | |
88 if story.allow_comments and forum_slug: | |
89 post_body = COMMENT_THREAD_BODY.format(title=story.title, | |
90 url=story.get_absolute_url()) | |
91 topic = create_topic(forum_slug, story.submitter, story.title, post_body) | |
92 story.forums_topic = topic | |
93 story.save() | |
76 | 94 |
77 class Media: | 95 class Media: |
78 js = ['js/news_admin.js'] + settings.GPP_THIRD_PARTY_JS['tiny_mce'] | 96 js = ['js/news_admin.js'] + settings.GPP_THIRD_PARTY_JS['tiny_mce'] |
79 | 97 |
80 | 98 |