annotate gpp/news/admin.py @ 265:1ba2c6bf6eb7

Closing #98. Animated GIFs were losing their transparency and animated properties when saved as avatars. Reworked the avatar save process to only run the avatar through PIL if it is too big. This preserves the original uploaded file if it is within the desired size settings. This may still mangle big animated gifs. If this becomes a problem, then maybe look into calling the PIL Image.resize() method directly. Moved the PIL image specific functions from bio.forms to a new module: core.image for better reusability in the future.
author Brian Neal <bgneal@gmail.com>
date Fri, 24 Sep 2010 02:12:09 +0000
parents 1246a4f1ab4f
children d424b8bae71d
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', )
gremmie@1 25
bgneal@204 26 def approve_story(self, request, qs):
bgneal@204 27 for pending_story in qs:
bgneal@204 28 story = Story(
bgneal@204 29 title=pending_story.title,
bgneal@204 30 submitter=pending_story.submitter,
bgneal@204 31 category=pending_story.category,
bgneal@204 32 short_text=pending_story.short_text,
bgneal@204 33 long_text=pending_story.long_text,
bgneal@204 34 date_submitted=datetime.datetime.now(),
bgneal@204 35 allow_comments=pending_story.allow_comments,
bgneal@218 36 tags=pending_story.tags,
bgneal@218 37 front_page_expiration=pending_story.front_page_expiration)
bgneal@204 38 story.save()
bgneal@204 39 pending_story.delete()
bgneal@204 40
bgneal@204 41 approve_story.short_description = "Approve selected pending stories"
bgneal@204 42
bgneal@204 43 class Media:
bgneal@204 44 js = settings.GPP_THIRD_PARTY_JS['tiny_mce']
gremmie@1 45
gremmie@1 46
gremmie@1 47 class StoryAdmin(admin.ModelAdmin):
bgneal@204 48 list_display = ('title', 'date_submitted', 'submitter', 'category')
bgneal@204 49 list_filter = ('date_submitted', 'category')
bgneal@204 50 search_fields = ('title', 'short_text', 'long_text')
bgneal@204 51 date_hierarchy = 'date_submitted'
gremmie@1 52
bgneal@204 53 class Media:
bgneal@204 54 js = settings.GPP_THIRD_PARTY_JS['tiny_mce']
gremmie@1 55
gremmie@1 56
bgneal@240 57 admin.site.register(Category, CategoryAdmin)
gremmie@1 58 admin.site.register(Story, StoryAdmin)
gremmie@1 59 admin.site.register(PendingStory, PendingStoryAdmin)