Skip to content

Commit

Permalink
Merge pull request #236 from collective/blob_paths_with_namedfile
Browse files Browse the repository at this point in the history
Fix AtributeError 'NamedFile' object has no attribute '_blob' when exporting objects with plone.namedfile.file.NamedFile properties
  • Loading branch information
valipod authored Jan 19, 2024
2 parents f96a3bd + c325f2d commit bae323d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
1 change: 1 addition & 0 deletions src/collective/exportimport/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<!-- Serializers -->
<adapter factory=".serializer.FileFieldSerializerWithBlobs" />
<adapter factory=".serializer.FileFieldSerializerWithBlobPaths" />
<adapter factory=".serializer.FileFieldSerializerZODBData" />
<adapter factory=".serializer.ImageFieldSerializerWithBlobs" />
<adapter factory=".serializer.ImageFieldSerializerWithBlobPaths" />
<adapter factory=".serializer.RichttextFieldSerializerWithRawText" />
Expand Down
11 changes: 10 additions & 1 deletion src/collective/exportimport/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bae323d

Please sign in to comment.