annotate 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
rev   line source
gremmie@1 1 """
gremmie@1 2 This file contains the automatic admin site definitions for the News models.
gremmie@1 3 """
bgneal@204 4 import datetime
gremmie@1 5
gremmie@1 6 from django.contrib import admin
bgneal@7 7 from django.conf import settings
bgneal@204 8 from django.core.cache import cache
bgneal@7 9
gremmie@1 10 from news.models import PendingStory
gremmie@1 11 from news.models import Story
gremmie@1 12 from news.models import Category
gremmie@1 13
gremmie@1 14 class PendingStoryAdmin(admin.ModelAdmin):
bgneal@204 15 list_display = ('title', 'date_submitted', 'submitter')
bgneal@204 16 list_filter = ('date_submitted', )
bgneal@204 17 search_fields = ('title', 'short_text', 'long_text')
bgneal@204 18 date_hierarchy = 'date_submitted'
bgneal@204 19 actions = ('approve_story', )
gremmie@1 20
bgneal@204 21 def approve_story(self, request, qs):
bgneal@204 22 for pending_story in qs:
bgneal@204 23 story = Story(
bgneal@204 24 title=pending_story.title,
bgneal@204 25 submitter=pending_story.submitter,
bgneal@204 26 category=pending_story.category,
bgneal@204 27 short_text=pending_story.short_text,
bgneal@204 28 long_text=pending_story.long_text,
bgneal@204 29 date_submitted=datetime.datetime.now(),
bgneal@204 30 allow_comments=pending_story.allow_comments,
bgneal@204 31 tags=pending_story.tags)
bgneal@204 32 story.save()
bgneal@204 33 pending_story.delete()
bgneal@204 34 cache.delete('home_news')
bgneal@204 35
bgneal@204 36 approve_story.short_description = "Approve selected pending stories"
bgneal@204 37
bgneal@204 38 class Media:
bgneal@204 39 js = settings.GPP_THIRD_PARTY_JS['tiny_mce']
gremmie@1 40
gremmie@1 41
gremmie@1 42 class StoryAdmin(admin.ModelAdmin):
bgneal@204 43 list_display = ('title', 'date_submitted', 'submitter', 'category')
bgneal@204 44 list_filter = ('date_submitted', 'category')
bgneal@204 45 search_fields = ('title', 'short_text', 'long_text')
bgneal@204 46 date_hierarchy = 'date_submitted'
gremmie@1 47
bgneal@204 48 class Media:
bgneal@204 49 js = settings.GPP_THIRD_PARTY_JS['tiny_mce']
gremmie@1 50
gremmie@1 51
gremmie@1 52 admin.site.register(Category)
gremmie@1 53 admin.site.register(Story, StoryAdmin)
gremmie@1 54 admin.site.register(PendingStory, PendingStoryAdmin)