comparison gpp/news/admin.py @ 204:b4305e18d3af

Resolve ticket #74. Add user badges. Some extra credit was done here: also refactored how pending news, links, and downloads are handled.
author Brian Neal <bgneal@gmail.com>
date Sat, 01 May 2010 21:53:59 +0000
parents ca66189c7c44
children 65016249bf35
comparison
equal deleted inserted replaced
203:40e5903903e1 204:b4305e18d3af
1 """ 1 """
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 import datetime
4 5
5 from django.contrib import admin 6 from django.contrib import admin
6 from django.conf import settings 7 from django.conf import settings
8 from django.core.cache import cache
7 9
8 from news.models import PendingStory 10 from news.models import PendingStory
9 from news.models import Story 11 from news.models import Story
10 from news.models import Category 12 from news.models import Category
11 13
12 class PendingStoryAdmin(admin.ModelAdmin): 14 class PendingStoryAdmin(admin.ModelAdmin):
13 list_display = ('title', 'date_submitted', 'submitter') 15 list_display = ('title', 'date_submitted', 'submitter')
14 list_filter = ('date_submitted', ) 16 list_filter = ('date_submitted', )
15 search_fields = ('title', 'short_text', 'long_text') 17 search_fields = ('title', 'short_text', 'long_text')
16 date_hierarchy = 'date_submitted' 18 date_hierarchy = 'date_submitted'
19 actions = ('approve_story', )
17 20
18 class Media: 21 def approve_story(self, request, qs):
19 js = settings.GPP_THIRD_PARTY_JS['tiny_mce'] 22 for pending_story in qs:
23 story = Story(
24 title=pending_story.title,
25 submitter=pending_story.submitter,
26 category=pending_story.category,
27 short_text=pending_story.short_text,
28 long_text=pending_story.long_text,
29 date_submitted=datetime.datetime.now(),
30 allow_comments=pending_story.allow_comments,
31 tags=pending_story.tags)
32 story.save()
33 pending_story.delete()
34 cache.delete('home_news')
35
36 approve_story.short_description = "Approve selected pending stories"
37
38 class Media:
39 js = settings.GPP_THIRD_PARTY_JS['tiny_mce']
20 40
21 41
22 class StoryAdmin(admin.ModelAdmin): 42 class StoryAdmin(admin.ModelAdmin):
23 list_display = ('title', 'date_published', 'submitter', 'category') 43 list_display = ('title', 'date_submitted', 'submitter', 'category')
24 list_filter = ('date_published', 'category') 44 list_filter = ('date_submitted', 'category')
25 search_fields = ('title', 'short_text', 'long_text') 45 search_fields = ('title', 'short_text', 'long_text')
26 date_hierarchy = 'date_published' 46 date_hierarchy = 'date_submitted'
27 47
28 class Media: 48 class Media:
29 js = settings.GPP_THIRD_PARTY_JS['tiny_mce'] 49 js = settings.GPP_THIRD_PARTY_JS['tiny_mce']
30 50
31 51
32 admin.site.register(Category) 52 admin.site.register(Category)
33 admin.site.register(Story, StoryAdmin) 53 admin.site.register(Story, StoryAdmin)
34 admin.site.register(PendingStory, PendingStoryAdmin) 54 admin.site.register(PendingStory, PendingStoryAdmin)