From 37e1ab369f1314cda21d43bd35eb9e4e4629f8a8 Mon Sep 17 00:00:00 2001 From: Xiaowu Zhang Date: Mon, 7 Oct 2019 17:03:59 +0200 Subject: [PATCH] BusinessTemplate: Import Big File's data property as Pdata --- product/ERP5/Document/BusinessTemplate.py | 3 +++ product/ERP5/tests/testBusinessTemplate.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/product/ERP5/Document/BusinessTemplate.py b/product/ERP5/Document/BusinessTemplate.py index ee0d3c1e227..3710ce57b0d 100644 --- a/product/ERP5/Document/BusinessTemplate.py +++ b/product/ERP5/Document/BusinessTemplate.py @@ -95,6 +95,7 @@ import threading from ZODB.broken import Broken, BrokenModified from Products.ERP5.genbt5list import BusinessTemplateRevision, \ item_name_list, item_set +from OFS.Image import File as OFSFile CACHE_DATABASE_PATH = None try: @@ -898,6 +899,8 @@ class ObjectTemplateItem(BaseTemplateItem): obj.__class__.__name__][1:] if unicode_data: data = data.decode(obj.output_encoding) + if isinstance(obj, OFSFile) and property_name == "data": + data = obj._read_data(data)[0] try: setattr(obj, property_name, data) except BrokenModified: diff --git a/product/ERP5/tests/testBusinessTemplate.py b/product/ERP5/tests/testBusinessTemplate.py index f4bf7588b24..8c19f176457 100644 --- a/product/ERP5/tests/testBusinessTemplate.py +++ b/product/ERP5/tests/testBusinessTemplate.py @@ -50,6 +50,7 @@ import string import tempfile import glob import sys +from OFS.Image import Pdata WORKFLOW_TYPE = 'erp5_workflow' @@ -7075,8 +7076,14 @@ class TestBusinessTemplate(BusinessTemplateMixin): self.assertEqual(file_content, expected_file_content) self.assertEqual(len(file_content), len(expected_file_content)) + def stepCheckFileisImportedAsPdata(self, sequence=None, **kw): + self.assertIsInstance(self.portal.portal_templates + .getInstalledBusinessTemplate('erp5_xhtml_style')._skin_item._objects + ['portal_skins/erp5_ckeditor/ckeditor/LICENSE.md'].data, Pdata) + def test_text_file_import_export(self): """ + First Check if file is imported as Pdata, then check the following case: When importing back ace.js containing a last line with whitespaces only, the last line was not imported, and thus the file could never been downloaded completely as its really size was less than the one on the File @@ -7084,6 +7091,8 @@ class TestBusinessTemplate(BusinessTemplateMixin): """ sequence_list = SequenceList() sequence_string = """ + CheckFileisImportedAsPdata + CreateSkinFolder CreateTextFile CheckTextFileContent -- 2.30.9