Skip to content

Commit

Permalink
Merge pull request #64 from collective/alecpm/fix-non-blob-crops
Browse files Browse the repository at this point in the history
Fix issue with crops disappearing for non-blob images (e.g. ATNewsItem images)
  • Loading branch information
tomgross committed Aug 9, 2015
2 parents 7285a28 + 3725ad7 commit f86eb66
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/plone/app/imagecropping/at.py
Expand Up @@ -43,8 +43,7 @@ def image_fields(self):
fields = []

for field in self.context.Schema().fields():
if IBlobImageField in providedBy(field).interfaces() or \
IImageField in providedBy(field).interfaces() and \
if IBlobImageField.providedBy(field) or IImageField.providedBy(field) and \
field.get_size(self.context) > 0:
fields.append(field)

Expand Down Expand Up @@ -124,7 +123,15 @@ class ImageTraverser(BaseImageTraverser):

def publishTraverse(self, request, name):
# remove scales information, if image has changed
if not hasattr(aq_base(self.context), blobScalesAttr) \
# We have no way of knowing if a non-blob image has changed, since we
# don't have a time marker for when crops were generated.
has_blobs = False
for field in self.context.Schema().fields():
if IBlobImageField.providedBy(field):
has_blobs = True
break

if has_blobs and not hasattr(aq_base(self.context), blobScalesAttr) \
and PAI_STORAGE_KEY in IAnnotations(self.context):
del IAnnotations(self.context)[PAI_STORAGE_KEY]
return super(ImageTraverser, self).publishTraverse(request, name)

0 comments on commit f86eb66

Please sign in to comment.