From 9afb41cf3517c3c3490fb18bfe4b8d7dd93c4316 Mon Sep 17 00:00:00 2001 From: Espen Moe-Nilssen Date: Wed, 17 Jul 2024 11:48:40 +0200 Subject: [PATCH 1/2] Use File field for other content types than Image or File --- src/onlyoffice/plone/core/fileUtils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/onlyoffice/plone/core/fileUtils.py b/src/onlyoffice/plone/core/fileUtils.py index 64c8906..3b7a52f 100644 --- a/src/onlyoffice/plone/core/fileUtils.py +++ b/src/onlyoffice/plone/core/fileUtils.py @@ -66,7 +66,11 @@ def getFileNameWithoutExt(context): def getFileExt(context): portal_type = context.portal_type - + + if hasattr(context, 'file'): + #Check if file contains data, for use with other content types than Image and File + filename = context.file.filename if context.file.getSize() and context.file.getSize() > 1 else None + if portal_type == "Image" : filename = context.image.filename if hasattr(context, "image") else None From 907a4f082dfa03351d7f90bbc89a5b328d1b8d50 Mon Sep 17 00:00:00 2001 From: Espen Moe-Nilssen Date: Thu, 29 Aug 2024 12:03:09 +0200 Subject: [PATCH 2/2] # Fallback for missing files / empty files --- src/onlyoffice/plone/core/fileUtils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/onlyoffice/plone/core/fileUtils.py b/src/onlyoffice/plone/core/fileUtils.py index 3b7a52f..700e508 100644 --- a/src/onlyoffice/plone/core/fileUtils.py +++ b/src/onlyoffice/plone/core/fileUtils.py @@ -66,10 +66,14 @@ def getFileNameWithoutExt(context): def getFileExt(context): portal_type = context.portal_type + filename = None + if hasattr(context, 'file'): - #Check if file contains data, for use with other content types than Image and File - filename = context.file.filename if context.file.getSize() and context.file.getSize() > 1 else None + #Check if content has uploaded file, in case required setting is disabled + if context.file is not None: + #Check if file contains data, for use with other content types than Image and File + filename = context.file.filename if context.file.getSize() and context.file.getSize() > 1 else None if portal_type == "Image" : filename = context.image.filename if hasattr(context, "image") else None