Commit 37e1ab36 authored by Xiaowu Zhang's avatar Xiaowu Zhang

BusinessTemplate: Import Big File's data property as Pdata

parent 969c3e23
...@@ -95,6 +95,7 @@ import threading ...@@ -95,6 +95,7 @@ import threading
from ZODB.broken import Broken, BrokenModified from ZODB.broken import Broken, BrokenModified
from Products.ERP5.genbt5list import BusinessTemplateRevision, \ from Products.ERP5.genbt5list import BusinessTemplateRevision, \
item_name_list, item_set item_name_list, item_set
from OFS.Image import File as OFSFile
CACHE_DATABASE_PATH = None CACHE_DATABASE_PATH = None
try: try:
...@@ -898,6 +899,8 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -898,6 +899,8 @@ class ObjectTemplateItem(BaseTemplateItem):
obj.__class__.__name__][1:] obj.__class__.__name__][1:]
if unicode_data: if unicode_data:
data = data.decode(obj.output_encoding) data = data.decode(obj.output_encoding)
if isinstance(obj, OFSFile) and property_name == "data":
data = obj._read_data(data)[0]
try: try:
setattr(obj, property_name, data) setattr(obj, property_name, data)
except BrokenModified: except BrokenModified:
......
...@@ -50,6 +50,7 @@ import string ...@@ -50,6 +50,7 @@ import string
import tempfile import tempfile
import glob import glob
import sys import sys
from OFS.Image import Pdata
WORKFLOW_TYPE = 'erp5_workflow' WORKFLOW_TYPE = 'erp5_workflow'
...@@ -7075,8 +7076,14 @@ class TestBusinessTemplate(BusinessTemplateMixin): ...@@ -7075,8 +7076,14 @@ class TestBusinessTemplate(BusinessTemplateMixin):
self.assertEqual(file_content, expected_file_content) self.assertEqual(file_content, expected_file_content)
self.assertEqual(len(file_content), len(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): 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, 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 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 downloaded completely as its really size was less than the one on the File
...@@ -7084,6 +7091,8 @@ class TestBusinessTemplate(BusinessTemplateMixin): ...@@ -7084,6 +7091,8 @@ class TestBusinessTemplate(BusinessTemplateMixin):
""" """
sequence_list = SequenceList() sequence_list = SequenceList()
sequence_string = """ sequence_string = """
CheckFileisImportedAsPdata
CreateSkinFolder CreateSkinFolder
CreateTextFile CreateTextFile
CheckTextFileContent CheckTextFileContent
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment