comparison news/admin.py @ 999:8386a8ebcbc7

WIP News v2.0 admin changes.
author Brian Neal <bgneal@gmail.com>
date Sat, 21 Nov 2015 14:53:29 -0600
parents 6dba56996a21
children c6c3ba5cf6eb
comparison
equal deleted inserted replaced
998:e2c3d7ecfa30 999:8386a8ebcbc7
20 list_display = ['title', 'date_submitted', 'submitter'] 20 list_display = ['title', 'date_submitted', 'submitter']
21 list_filter = ['date_submitted'] 21 list_filter = ['date_submitted']
22 search_fields = ['title', 'short_text', 'long_text'] 22 search_fields = ['title', 'short_text', 'long_text']
23 date_hierarchy = 'date_submitted' 23 date_hierarchy = 'date_submitted'
24 actions = ['approve_story'] 24 actions = ['approve_story']
25 readonly_fields = ['update_date'] 25 readonly_fields = ['update_date', 'version']
26 raw_id_fields = ['submitter'] 26 raw_id_fields = ['submitter']
27
28 fieldsets = [
29 (None, {
30 'fields': ['title', 'submitter', 'category'],
31 }),
32 ('New Markdown Fields', {
33 'fields': ['short_markup', 'long_markup'],
34 }),
35 ('HTML Fields', {
36 'fields': ['short_text', 'long_text', 'admin_content'],
37 'classes': ['collapse'],
38 }),
39 ('Meta Fields', {
40 'fields': [
41 'date_submitted', 'allow_comments', 'tags',
42 'front_page_expiration', 'priority', 'meta_description',
43 ]
44 }),
45 ('Read-Only Fields', {
46 'fields': ['update_date', 'version'],
47 'classes': ['collapse'],
48 }),
49 ]
27 50
28 def approve_story(self, request, qs): 51 def approve_story(self, request, qs):
29 for pending_story in qs: 52 for pending_story in qs:
30 story = Story( 53 story = Story(
31 title=pending_story.title, 54 title=pending_story.title,
36 date_submitted=pending_story.date_submitted, 59 date_submitted=pending_story.date_submitted,
37 allow_comments=pending_story.allow_comments, 60 allow_comments=pending_story.allow_comments,
38 tags=pending_story.tags, 61 tags=pending_story.tags,
39 front_page_expiration=pending_story.front_page_expiration, 62 front_page_expiration=pending_story.front_page_expiration,
40 priority=pending_story.priority, 63 priority=pending_story.priority,
41 meta_description=pending_story.meta_description) 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)
42 story.save() 68 story.save()
43 pending_story.delete() 69 pending_story.delete()
44 70
45 count = len(qs) 71 count = len(qs)
46 msg = "1 story" if count == 1 else "%d stories" % count 72 msg = "1 story" if count == 1 else "%d stories" % count
55 class StoryAdmin(admin.ModelAdmin): 81 class StoryAdmin(admin.ModelAdmin):
56 list_display = ['title', 'date_submitted', 'submitter', 'category'] 82 list_display = ['title', 'date_submitted', 'submitter', 'category']
57 list_filter = ['date_submitted', 'category'] 83 list_filter = ['date_submitted', 'category']
58 search_fields = ['title', 'short_text', 'long_text'] 84 search_fields = ['title', 'short_text', 'long_text']
59 date_hierarchy = 'date_submitted' 85 date_hierarchy = 'date_submitted'
60 readonly_fields = ['update_date'] 86 readonly_fields = ['update_date', 'version']
61 raw_id_fields = ['submitter'] 87 raw_id_fields = ['submitter']
62 actions = ['fix_text'] 88 actions = ['fix_text']
89
90 fieldsets = PendingStoryAdmin.fieldsets
63 91
64 def fix_text(self, request, qs): 92 def fix_text(self, request, qs):
65 for story in qs: 93 for story in qs:
66 story.title = ftfy.fix_text(story.title) 94 story.title = ftfy.fix_text(story.title)
67 story.short_text = ftfy.fix_text(story.short_text) 95 story.short_text = ftfy.fix_text(story.short_text)