Commit c5453025 authored by Xiaowu Zhang's avatar Xiaowu Zhang Committed by Levin Zimmermann

BusinessTemplate: Import Big File's data property as Pdata

When i upgrade/install erp5_notebook in an instance which use neo storage instead
of zeo, Neo stopped immediately, as consequence, erp5_notebook can't be installed/upgraded.

The reason is in erp5_notebook, there has a one big file scipy.data.bin 157MB [1] which can't be
installed as it is  in neo. The solution suggested by @jm is to wrapper it by Pdata when install
a BT5.

See merge request nexedi/erp5!953

[1] https://lab.nexedi.com/nexedi/erp5-bin/blob/7d3505fd/bt5/erp5_notebook/SkinTemplateItem/portal_skins/erp5_notebook/scipy.data.bin
parent 149fdd1d
...@@ -46,6 +46,7 @@ import string ...@@ -46,6 +46,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'
...@@ -7262,8 +7263,14 @@ class TestBusinessTemplate(BusinessTemplateMixin): ...@@ -7262,8 +7263,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
...@@ -7271,6 +7278,8 @@ class TestBusinessTemplate(BusinessTemplateMixin): ...@@ -7271,6 +7278,8 @@ class TestBusinessTemplate(BusinessTemplateMixin):
""" """
sequence_list = SequenceList() sequence_list = SequenceList()
sequence_string = """ sequence_string = """
CheckFileisImportedAsPdata
CreateSkinFolder CreateSkinFolder
CreateTextFile CreateTextFile
CheckTextFileContent CheckTextFileContent
......
...@@ -99,6 +99,7 @@ from ZODB.broken import Broken, BrokenModified ...@@ -99,6 +99,7 @@ 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 Products.ERP5Type.mixin.component import ComponentMixin from Products.ERP5Type.mixin.component import ComponentMixin
from OFS.Image import File as OFSFile
CACHE_DATABASE_PATH = None CACHE_DATABASE_PATH = None
try: try:
...@@ -878,6 +879,8 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -878,6 +879,8 @@ class ObjectTemplateItem(BaseTemplateItem):
# backward-compatibility # backward-compatibility
elif six.PY3 and is_text: elif six.PY3 and is_text:
data = data.decode('utf-8') data = data.decode('utf-8')
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:
......
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