mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-04-07 15:20:57 +00:00
Fix bug when imgfield doesn't exist.
This commit is contained in:
parent
a60dfba31d
commit
98a5ca32b4
1 changed files with 19 additions and 18 deletions
|
|
@ -259,24 +259,25 @@ def _post_save_handler(sender, instance=None, created=False, raw=False, **kwargs
|
|||
bound_specs = get_bound_specs(instance)
|
||||
for bound_spec in bound_specs:
|
||||
name = bound_spec.attname
|
||||
imgfield = bound_spec._get_imgfield(instance)
|
||||
newfile = imgfield.storage.open(str(imgfield))
|
||||
img = Image.open(newfile)
|
||||
img, format = bound_spec.process(img, instance)
|
||||
if format != 'JPEG':
|
||||
imgfile = img_to_fobj(img, format)
|
||||
else:
|
||||
imgfile = img_to_fobj(img, format,
|
||||
quality=int(bound_spec.quality),
|
||||
optimize=True)
|
||||
content = ContentFile(imgfile.read())
|
||||
newfile.close()
|
||||
name = str(imgfield)
|
||||
imgfield.storage.delete(name)
|
||||
imgfield.storage.save(name, content)
|
||||
if not created:
|
||||
bound_spec._delete()
|
||||
bound_spec._create()
|
||||
imgfield = bound_spec._imgfield
|
||||
if imgfield:
|
||||
newfile = imgfield.storage.open(imgfield.name)
|
||||
img = Image.open(newfile)
|
||||
img, format = bound_spec.process(img, instance)
|
||||
if format != 'JPEG':
|
||||
imgfile = img_to_fobj(img, format)
|
||||
else:
|
||||
imgfile = img_to_fobj(img, format,
|
||||
quality=int(bound_spec.quality),
|
||||
optimize=True)
|
||||
content = ContentFile(imgfile.read())
|
||||
newfile.close()
|
||||
name = str(imgfield)
|
||||
imgfield.storage.delete(name)
|
||||
imgfield.storage.save(name, content)
|
||||
if not created:
|
||||
bound_spec._delete()
|
||||
bound_spec._create()
|
||||
|
||||
|
||||
def _post_delete_handler(sender, instance=None, **kwargs):
|
||||
|
|
|
|||
Loading…
Reference in a new issue