Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use in Plone 4.3 with dexterity but without z3c.relationfield. #33

Merged
merged 1 commit into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Changelog
- Fix use in Plone 4.3 without dexterity, zc.relation or plone.app.contenttypes.
[pbauer]

- Fix use in Plone 4.3 with dexterity but without z3c.relationfield.
[maurits]


1.0 (2021-04-27)
----------------

Expand Down
2 changes: 2 additions & 0 deletions src/collective/exportimport/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
<adapter factory=".serializer.FileFieldSerializerWithBlobs" />
<adapter factory=".serializer.ImageFieldSerializerWithBlobs" />
<adapter factory=".serializer.RichttextFieldSerializerWithRawText" />
<adapter zcml:condition="installed z3c.relationfield"
factory=".export_content.relationvalue_converter_uuid" />

<browser:page
name="exportimport_links"
Expand Down
41 changes: 29 additions & 12 deletions src/collective/exportimport/export_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,31 @@
from Products.Archetypes.interfaces import IBaseObject
HAS_AT = True


try:
pkg_resources.get_distribution("plone.dexterity")
pkg_resources.get_distribution("z3c.relationfield")
except pkg_resources.DistributionNotFound:
IDexterityContent = None
IDexterityFTI = None
iterSchemata = None
IRelationChoice = None
IRelationList = None
IRelationValue = None
HAS_DX = False
else:
from plone.dexterity.interfaces import IDexterityContent
from plone.dexterity.interfaces import IDexterityFTI
from plone.dexterity.utils import iterSchemata
HAS_DX = True

try:
pkg_resources.get_distribution("z3c.relationfield")
except pkg_resources.DistributionNotFound:
IRelationChoice = None
IRelationList = None
IRelationValue = None
HAS_RELATIONS = False
else:
from z3c.relationfield.interfaces import IRelationChoice
from z3c.relationfield.interfaces import IRelationList
from z3c.relationfield.interfaces import IRelationValue
HAS_DX = True
HAS_RELATIONS = True


logger = logging.getLogger(__name__)
Expand All @@ -83,6 +88,19 @@
}


def is_dx_or_at_fti(fti):
"""Return True if the FTI is a Dexterity or Archetypes type.

This is a small helper function to avoid having too many
nots/ands/ors in a condition.
"""
if IDynamicViewTypeInformation.providedBy(fti):
return True
if not HAS_DX:
return False
return IDexterityFTI.providedBy(fti)


class ExportContent(BrowserView):

template = ViewPageTemplateFile("templates/export_content.pt")
Expand Down Expand Up @@ -215,10 +233,9 @@ def portal_types(self):
results = []
query = self.build_query()
for fti in portal_types.listTypeInfo():
if not IDexterityFTI.providedBy(
fti
) and not IDynamicViewTypeInformation.providedBy(fti):
# Ignore non-DX and non-AT types
if not is_dx_or_at_fti(fti):
# Ignore non-DX and non-AT types,
# for example ATBooleanCriterion and TempFolder.
continue
query["portal_type"] = fti.id
number = len(catalog.unrestrictedSearchResults(**query))
Expand Down Expand Up @@ -285,7 +302,7 @@ def update_data_for_migration(self, item, obj):
for field in obj.schema.fields():
if isinstance(field, ReferenceField):
item.pop(field.__name__, None)
elif HAS_DX and IDexterityContent.providedBy(obj):
elif HAS_DX and HAS_RELATIONS and IDexterityContent.providedBy(obj):
for schema in iterSchemata(obj):
for name, field in getFields(schema).items():
if IRelationChoice.providedBy(field) or IRelationList.providedBy(field):
Expand Down Expand Up @@ -340,7 +357,7 @@ def migrate_field(item, old, new):
return item


if HAS_DX:
if HAS_RELATIONS:
@adapter(IRelationValue)
@implementer(IJsonCompatible)
def relationvalue_converter_uuid(value):
Expand Down