mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-04-04 22:10:24 +00:00
A list of ImageSpec names are now stored on the model.
Previously, ImageSpecFile instances were retrieved (for saving and deleting, among other possibilities) by iterating over the model instance's attributes. This change adds ImageSpecFile names to a list (spec_file_names) on an imagekit meta object on the model (_ik), making later retrieval much cheaper and more straightforward.
This commit is contained in:
parent
b9aa69e0c0
commit
b8e57dccd6
2 changed files with 13 additions and 10 deletions
|
|
@ -77,6 +77,13 @@ class ImageSpec(_ImageSpecMixin):
|
|||
|
||||
def contribute_to_class(self, cls, name):
|
||||
setattr(cls, name, _ImageSpecDescriptor(self, name))
|
||||
try:
|
||||
ik = getattr(cls, '_ik')
|
||||
except AttributeError:
|
||||
ik = type('ImageKitMeta', (object,), {'spec_file_names': []})
|
||||
setattr(cls, '_ik', ik)
|
||||
ik.spec_file_names.append(name)
|
||||
|
||||
# Connect to the signals only once for this class.
|
||||
uid = '%s.%s' % (cls.__module__, cls.__name__)
|
||||
post_save.connect(_post_save_handler,
|
||||
|
|
|
|||
|
|
@ -13,16 +13,12 @@ def img_to_fobj(img, format, **kwargs):
|
|||
|
||||
|
||||
def get_spec_files(instance):
|
||||
from imagekit.models import ImageSpecFile
|
||||
spec_files = []
|
||||
for key in dir(instance):
|
||||
try:
|
||||
value = getattr(instance, key)
|
||||
except AttributeError:
|
||||
continue
|
||||
if isinstance(value, ImageSpecFile):
|
||||
spec_files.append(value)
|
||||
return spec_files
|
||||
try:
|
||||
ik = getattr(instance, '_ik')
|
||||
except AttributeError:
|
||||
return []
|
||||
else:
|
||||
return [getattr(instance, n) for n in ik.spec_file_names]
|
||||
|
||||
|
||||
def open_image(target):
|
||||
|
|
|
|||
Loading…
Reference in a new issue