annotate gpp/news/admin.py @ 480:1a7ca5fa494f

Fixing #229: Download details view with a bogus download ID produces internal server error isntead of a 404.
author Brian Neal <bgneal@gmail.com>
date Wed, 05 Oct 2011 00:09:30 +0000
parents 53fdaf0da539
children 7854d75427af
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@7 8
gremmie@1 9 from news.models import PendingStory
gremmie@1 10 from news.models import Story
gremmie@1 11 from news.models import Category
gremmie@1 12
bgneal@240 13
bgneal@240 14 class CategoryAdmin(admin.ModelAdmin):
bgneal@240 15 prepopulated_fields = {'slug': ("title", )}
bgneal@240 16 list_display = ('title', 'slug')
bgneal@240 17
bgneal@240 18
gremmie@1 19 class PendingStoryAdmin(admin.ModelAdmin):
bgneal@204 20 list_display = ('title', 'date_submitted', 'submitter')
bgneal@204 21 list_filter = ('date_submitted', )
bgneal@204 22 search_fields = ('title', 'short_text', 'long_text')
bgneal@204 23 date_hierarchy = 'date_submitted'
bgneal@204 24 actions = ('approve_story', )
bgneal@277 25 readonly_fields = ('update_date', )
bgneal@372 26 raw_id_fields = ('submitter', )
gremmie@1 27
bgneal@204 28 def approve_story(self, request, qs):
bgneal@204 29 for pending_story in qs:
bgneal@204 30 story = Story(
bgneal@204 31 title=pending_story.title,
bgneal@204 32 submitter=pending_story.submitter,
bgneal@204 33 category=pending_story.category,
bgneal@204 34 short_text=pending_story.short_text,
bgneal@204 35 long_text=pending_story.long_text,
bgneal@277 36 date_submitted=pending_story.date_submitted,
bgneal@204 37 allow_comments=pending_story.allow_comments,
bgneal@218 38 tags=pending_story.tags,
bgneal@462 39 front_page_expiration=pending_story.front_page_expiration,
bgneal@462 40 priority=pending_story.priority)
bgneal@204 41 story.save()
bgneal@204 42 pending_story.delete()
bgneal@204 43
bgneal@398 44 count = len(qs)
bgneal@398 45 msg = "1 story" if count == 1 else "%d stories" % count
bgneal@398 46 self.message_user(request, "%s approved." % msg)
bgneal@398 47
bgneal@204 48 approve_story.short_description = "Approve selected pending stories"
bgneal@204 49
bgneal@204 50 class Media:
bgneal@204 51 js = settings.GPP_THIRD_PARTY_JS['tiny_mce']
gremmie@1 52
gremmie@1 53
gremmie@1 54 class StoryAdmin(admin.ModelAdmin):
bgneal@204 55 list_display = ('title', 'date_submitted', 'submitter', 'category')
bgneal@204 56 list_filter = ('date_submitted', 'category')
bgneal@204 57 search_fields = ('title', 'short_text', 'long_text')
bgneal@204 58 date_hierarchy = 'date_submitted'
bgneal@277 59 readonly_fields = ('update_date', )
bgneal@372 60 raw_id_fields = ('submitter', )
gremmie@1 61
bgneal@204 62 class Media:
bgneal@204 63 js = settings.GPP_THIRD_PARTY_JS['tiny_mce']
gremmie@1 64
gremmie@1 65
bgneal@240 66 admin.site.register(Category, CategoryAdmin)
gremmie@1 67 admin.site.register(Story, StoryAdmin)
gremmie@1 68 admin.site.register(PendingStory, PendingStoryAdmin)