annotate gpp/potd/admin.py @ 445:e9f203c5f5bb

Attempting to fix #218; update the topic last visit time with 'now' when viewing the last page of a topic, otherwise use the creation time of the last post on the page.
author Brian Neal <bgneal@gmail.com>
date Wed, 08 Jun 2011 00:24:41 +0000
parents 3c951521e0ec
children 4021ea1045f7
rev   line source
gremmie@1 1 """
gremmie@1 2 This file contains the admin definitions for the POTD application.
gremmie@1 3 """
bgneal@267 4 from django.contrib import admin
bgneal@267 5 from django.conf import settings
gremmie@1 6
gremmie@1 7 from potd.models import Photo
gremmie@1 8 from potd.models import Current
gremmie@1 9 from potd.models import Sequence
gremmie@1 10
bgneal@267 11
bgneal@330 12 IMG_TAG = '<img src="%s" alt="thumbnail" />'
bgneal@330 13
bgneal@330 14
gremmie@1 15 class PhotoAdmin(admin.ModelAdmin):
bgneal@330 16 fields = ('photo', 'caption', 'description', 'user', 'potd_count')
gremmie@1 17 raw_id_fields = ('user', )
bgneal@330 18 list_display = ('__unicode__', 'thumbnail')
bgneal@330 19 actions = ('regen_thumbnail', )
gremmie@1 20
bgneal@267 21 class Media:
bgneal@267 22 js = settings.GPP_THIRD_PARTY_JS['tiny_mce']
bgneal@267 23
bgneal@330 24 def thumbnail(self, obj):
bgneal@330 25 return IMG_TAG % obj.thumb.url
bgneal@330 26 thumbnail.allow_tags = True
bgneal@330 27
bgneal@330 28 def regen_thumbnail(self, request, qs):
bgneal@330 29 """
bgneal@330 30 Regenerates the thumbnail for the selected photos.
bgneal@330 31 """
bgneal@330 32 for photo in qs:
bgneal@330 33 photo.generate_thumb()
bgneal@330 34 photo.save()
bgneal@330 35
bgneal@330 36 regen_thumbnail.short_description = "Regenerate thumbs for selected photos"
bgneal@330 37
bgneal@330 38
gremmie@1 39 class CurrentAdmin(admin.ModelAdmin):
bgneal@330 40 list_display = ('__unicode__', 'thumbnail')
gremmie@1 41 raw_id_fields = ('potd', )
gremmie@1 42
bgneal@330 43 def thumbnail(self, obj):
bgneal@330 44 return IMG_TAG % obj.potd.thumb.url
bgneal@330 45 thumbnail.allow_tags = True
bgneal@330 46
bgneal@330 47
gremmie@1 48 admin.site.register(Photo, PhotoAdmin)
gremmie@1 49 admin.site.register(Current, CurrentAdmin)
gremmie@1 50 admin.site.register(Sequence)