From 5c25ec7357b06295cf0bdc52fbae19e935be0936 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Sun, 12 Nov 2023 14:27:36 +0100 Subject: [PATCH] Improve code-reusage. --- src/collective/exportimport/serializer.py | 28 ++++------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/src/collective/exportimport/serializer.py b/src/collective/exportimport/serializer.py index 8b28a58f..2eed52f2 100644 --- a/src/collective/exportimport/serializer.py +++ b/src/collective/exportimport/serializer.py @@ -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): @@ -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):