mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-04-16 11:11:01 +00:00
Admin thumbnails.
This commit is contained in:
parent
a1f11facbe
commit
5e00de5204
3 changed files with 22 additions and 18 deletions
|
|
@ -20,5 +20,4 @@ class PNGFormat(processors.Format):
|
|||
extension = 'png'
|
||||
|
||||
class DjangoAdminThumbnail(ImageSpec):
|
||||
access_as = 'admin_thumbnail'
|
||||
processors = [ResizeThumbnail, EnhanceSmall, SampleReflection, PNGFormat]
|
||||
processors = [ResizeThumbnail(), EnhanceSmall(), SampleReflection(), PNGFormat()]
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ from imagekit.specs import ImageSpec, Descriptor
|
|||
from imagekit.lib import *
|
||||
from imagekit.options import Options
|
||||
from imagekit.utils import img_to_fobj
|
||||
from imagekit import defaults
|
||||
|
||||
# Modify image file buffer size.
|
||||
ImageFile.MAXBLOCK = getattr(settings, 'PIL_IMAGEFILE_MAXBLOCK', 256 * 2 ** 10)
|
||||
|
|
@ -39,18 +40,17 @@ class ImageModelBase(ModelBase):
|
|||
|
||||
"""
|
||||
def __init__(self, name, bases, attrs):
|
||||
if [b for b in bases if isinstance(b, ImageModelBase)]:
|
||||
user_opts = getattr(self, 'IKOptions', None)
|
||||
|
||||
specs = []
|
||||
for k, v in attrs.items():
|
||||
if isinstance(v, ImageSpec):
|
||||
setattr(self, k, Descriptor(v, k))
|
||||
specs.append(v)
|
||||
|
||||
user_opts.specs = specs
|
||||
opts = Options(user_opts)
|
||||
setattr(self, '_ik', opts)
|
||||
user_opts = getattr(self, 'IKOptions', None)
|
||||
|
||||
specs = []
|
||||
for k, v in attrs.items():
|
||||
if isinstance(v, ImageSpec):
|
||||
setattr(self, k, Descriptor(v, k))
|
||||
specs.append(v)
|
||||
|
||||
user_opts.specs = specs
|
||||
opts = Options(user_opts)
|
||||
setattr(self, '_ik', opts)
|
||||
ModelBase.__init__(self, name, bases, attrs)
|
||||
|
||||
|
||||
|
|
@ -64,16 +64,18 @@ class ImageModel(models.Model):
|
|||
"""
|
||||
__metaclass__ = ImageModelBase
|
||||
|
||||
admin_thumbnail = defaults.DjangoAdminThumbnail()
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def admin_thumbnail_view(self):
|
||||
if not self._imgfield:
|
||||
return None
|
||||
prop = getattr(self, self._ik.admin_thumbnail_spec, None)
|
||||
prop = getattr(self, self._ik.admin_thumbnail_property, None)
|
||||
if prop is None:
|
||||
return 'An "%s" image spec has not been defined.' % \
|
||||
self._ik.admin_thumbnail_spec
|
||||
return 'The property "%s" has not been defined.' % \
|
||||
self._ik.admin_thumbnail_property
|
||||
else:
|
||||
if hasattr(self, 'get_absolute_url'):
|
||||
return u'<a href="%s"><img src="%s"></a>' % \
|
||||
|
|
|
|||
|
|
@ -7,6 +7,10 @@ class Options(object):
|
|||
""" Class handling per-model imagekit options
|
||||
|
||||
"""
|
||||
|
||||
admin_thumbnail_property = 'admin_thumbnail'
|
||||
"""The name of the spec to be used by the admin_thumbnail_view"""
|
||||
|
||||
image_field = 'image'
|
||||
crop_horz_field = 'crop_horz'
|
||||
crop_vert_field = 'crop_vert'
|
||||
|
|
@ -15,7 +19,6 @@ class Options(object):
|
|||
save_count_as = None
|
||||
cache_filename_fields = ['pk', ]
|
||||
cache_filename_format = "%(filename)s_%(specname)s.%(extension)s"
|
||||
admin_thumbnail_spec = 'admin_thumbnail'
|
||||
specs = None
|
||||
#storage = defaults to image_field.storage
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue