Skip to content

Commit

Permalink
Merge pull request #36 from iham/master
Browse files Browse the repository at this point in the history
Fixed CloneBlobs modifier to only react on Archetypes.
  • Loading branch information
jensens committed Apr 4, 2016
2 parents 832b754 + 68807c8 commit fb2ded6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ New:

Fixes:

- *add item here*
- Fixed CloneBlobs modifier to only react on Archetypes.
This fix allows Dexterity Blob-Types (e.g. File, Image) to be versioned.
[iham]


2.2.19 (2016-02-14)
Expand Down
18 changes: 17 additions & 1 deletion Products/CMFEditions/StandardModifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
from Products.CMFEditions.Modifiers import ConditionalModifier
from Products.CMFEditions.Modifiers import ConditionalTalesModifier

try:
from Products.Archetypes.interfaces.base import IBaseContent
except ImportError:
class IBaseContent(Interface):
pass
try:
from Products.Archetypes.interfaces.referenceable import IReferenceable
from Products.Archetypes.config import UUID_ATTR, REFERENCE_ANNOTATION
Expand Down Expand Up @@ -1167,9 +1172,16 @@ class CloneBlobs:
implements(IAttributeModifier, ICloneModifier)

def getReferencedAttributes(self, obj):

file_data = {}

# This modifier should only be used for ATCT
# so return the empty file_data if not an ATCT
if not IBaseContent.providedBy(obj):
return file_data

blob_fields = (f for f in obj.Schema().fields()
if IBlobField.providedBy(f))
file_data = {}
# try to get last revision, only store a new blob if the
# contents differ from the prior one, otherwise store a
# reference to the prior one
Expand Down Expand Up @@ -1221,6 +1233,10 @@ def reattachReferencedAttributes(self, obj, attrs_dict):
def getOnCloneModifiers(self, obj):
"""Removes references to blobs.
"""
# Fix for Dexterity Types
if not IBaseContent.providedBy(obj):
return None

blob_refs = dict((id(f.getUnwrapped(obj, raw=True).getBlob()), True)
for f in obj.Schema().fields()
if IBlobField.providedBy(f))
Expand Down

0 comments on commit fb2ded6

Please sign in to comment.