Skip to content

Commit

Permalink
Improve code-reusage.
Browse files Browse the repository at this point in the history
  • Loading branch information
thet committed Nov 12, 2023
1 parent e9227ee commit 5c25ec7
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions src/collective/exportimport/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,6 @@ def get_blob_path(blob):

# Custom Serializers for Dexterity

@adapter(INamedImageField, IDexterityContent, IBase64BlobsMarker)
class ImageFieldSerializerWithBlobs(DefaultFieldSerializer):
def __call__(self):
try:
image = self.field.get(self.context)
except AttributeError:
image = None
if not image:
return None

if "built-in function id" in image.filename:
filename = self.context.id
else:
filename = image.filename

result = {
"filename": filename,
"content-type": image.contentType,
"data": base64.b64encode(image.data),
"encoding": "base64",
}
return json_compatible(result)


@adapter(INamedFileField, IDexterityContent, IBase64BlobsMarker)
class FileFieldSerializerWithBlobs(DefaultFieldSerializer):
Expand Down Expand Up @@ -140,6 +117,11 @@ def __call__(self):
return json_compatible(result)


@adapter(INamedImageField, IDexterityContent, IBase64BlobsMarker)
class ImageFieldSerializerWithBlobs(FileFieldSerializerWithBlobs):
pass


@adapter(IRichText, IDexterityContent, IRawRichTextMarker)
class RichttextFieldSerializerWithRawText(DefaultFieldSerializer):
def __call__(self):
Expand Down

0 comments on commit 5c25ec7

Please sign in to comment.