diff --git a/CHANGES.rst b/CHANGES.rst index 724d5fa4..515fc44b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,11 @@ Changelog 1.11 (unreleased) ----------------- +- Fix ``AtributeError: 'NamedFile' object has no attribute '_blob'`` when using setting + "Include blobs as blob paths" and exporting objects with + plone.namedfile.file.NamedFile properties (so not blobs). + [valipod] + - Add more Python 2 compatible version specifications and update the README. [thet] diff --git a/src/collective/exportimport/configure.zcml b/src/collective/exportimport/configure.zcml index 6e7cf577..9aef47fb 100644 --- a/src/collective/exportimport/configure.zcml +++ b/src/collective/exportimport/configure.zcml @@ -130,6 +130,7 @@ + diff --git a/src/collective/exportimport/serializer.py b/src/collective/exportimport/serializer.py index 2eed52f2..1f303ba2 100644 --- a/src/collective/exportimport/serializer.py +++ b/src/collective/exportimport/serializer.py @@ -7,7 +7,7 @@ from hurry.filesize import size from plone.app.textfield.interfaces import IRichText from plone.dexterity.interfaces import IDexterityContent -from plone.namedfile.interfaces import INamedFileField +from plone.namedfile.interfaces import INamedFileField, INamedBlobFileField from plone.namedfile.interfaces import INamedImageField from plone.restapi.interfaces import IFieldSerializer from plone.restapi.interfaces import IJsonCompatible @@ -549,6 +549,15 @@ def get_dx_blob_path(obj): @adapter(INamedFileField, IDexterityContent, IPathBlobsMarker) @implementer(IFieldSerializer) +class FileFieldSerializerZODBData(FileFieldSerializerWithBlobs): + """ Although the marker is IPathBlobsMarker, this being a plain NamedFile + object, its data is in the ZODB, thus this still needs to be + base64 encoded into the JSON file + So we just subclass from the above FileFieldSerializerWithBlobs """ + + +@adapter(INamedBlobFileField, IDexterityContent, IPathBlobsMarker) +@implementer(IFieldSerializer) class FileFieldSerializerWithBlobPaths(DefaultFieldSerializer): def __call__(self): namedfile = self.field.get(self.context)