Skip to content

Commit

Permalink
Check, if wrapper methods for Zope/CMF objects are Zope/CMF only obje…
Browse files Browse the repository at this point in the history
…cts by testing for Archetypes and Dexterity first.
  • Loading branch information
thet committed Feb 27, 2015
1 parent 8b1bd83 commit 23ecdc3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
6 changes: 5 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changelog
0.3 (unreleased)
----------------

- Check, if wrapper methods for Zope/CMF objects are Zope/CMF only objects by
testing for Archetypes and Dexterity first.
[thet]

- Add ``BlobField`` for ``get_archetypes_fields``.
[thet]

Expand All @@ -22,7 +26,7 @@ Changelog
- Fix read of NamedBlobImage, NamedFile and NamedBlobFile in dexterity objects.
[djowett]

- Fix read of field for unicode transcoding in dexterity objects.
- Fix read of field for unicode transcoding in dexterity objects.
[djowett]

- Make ``archetypes.schemaextender`` support more generic and handle probably
Expand Down
40 changes: 28 additions & 12 deletions collective/jsonify/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,36 @@ def get_id(self):
"""
self['_id'] = self.context.getId()

def get_zope_dublin_core(self):
"""If CMFCore is used in an old Zope site, then dump the
Dublin Core fields
def _is_cmf_only_obj(self):
"""Test, if a content item is a CMF only object.
"""
context = self.context
try:
from Products.ATContentTypes.interfaces import IATContentType
if IATContentType.providedBy(context):
return False
except:
pass
try:
from plone.dexterity.interfaces import IDexterityContent
if IDexterityContent.providedBy(context):
return False
except:
pass
try:
from Products.CMFCore.DynamicType import DynamicType
# restrict this to non archetypes/dexterity
if not isinstance(self.context, DynamicType):
# Not a CMFCore type
return
if isinstance(context, DynamicType):
return True
except:
pass
return False

def get_zope_dublin_core(self):
"""If CMFCore is used in an old Zope site, then dump the
Dublin Core fields
"""
if not self._is_cmf_only_obj():
return

# strings
Expand Down Expand Up @@ -299,12 +318,7 @@ def get_zope_cmfcore_fields(self):
"""If CMFCore is used in an old Zope site, then dump the fields we know
about.
"""
try:
from Products.CMFCore.DynamicType import DynamicType
if not isinstance(self.context, DynamicType):
# Not a CMFCore type
return
except:
if not self._is_cmf_only_obj():
return

self['_cmfcore_marker'] = 'yes'
Expand Down Expand Up @@ -393,6 +407,8 @@ def get_zope_cmfcore_fields(self):
}

def get_zopeobject_document_src(self):
if not self._is_cmf_only_obj():
return
document_src = getattr(self.context, 'document_src', None)
if document_src:
self['document_src'] = self.decode(document_src())
Expand Down

0 comments on commit 23ecdc3

Please sign in to comment.