Commit a452522d authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki Committed by Jérome Perrin

WIP: py2/py3: store file content as it is in Business Template for PathTemplateItem.

If we have a portal_type definition and its instances in the same Business Template,
_importFile() creates broken objects in PathTemplateItem._objects for such instances and
they will be 'fixed' in install() timing. But in Python 3, it does not work because :

while importing a content file, like *.js...

(BusinessTemplate.py)
     try:
       setattr(obj, property_name, data)
     except BrokenModified:
       obj.__Broken_state__[property_name] = data # <-- !!!
       obj._p_changed = 1

obj.__Broken_state__ access here also raises BrokenModified.

while importing an XML file...

(ZODB/broken.py)
    def __new__(class_, *args):
        result = object.__new__(class_) # <-- !!!
        result.__dict__['__Broken_newargs__'] = args
        return result

we get an exception 'TypeError: object.__new__(Portal Type) is not safe, use Base.__new__()'
parent d8a856de
...@@ -940,7 +940,7 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -940,7 +940,7 @@ class ObjectTemplateItem(BaseTemplateItem):
# ObjectTemplateItem.__init__() # ObjectTemplateItem.__init__()
# XXX - the above comment is a bit unclear, # XXX - the above comment is a bit unclear,
# still not sure if this is handled correctly # still not sure if this is handled correctly
if file_obj.name.rsplit(os.path.sep, 2)[-2] == 'portal_components': if obj_key.split(os.path.sep, 1)[0] == 'portal_components':
self._archive[obj_key] = None self._archive[obj_key] = None
try: try:
del self._archive[obj_key[len('portal_components/'):]] del self._archive[obj_key[len('portal_components/'):]]
...@@ -1678,6 +1678,7 @@ class PathTemplateItem(ObjectTemplateItem): ...@@ -1678,6 +1678,7 @@ class PathTemplateItem(ObjectTemplateItem):
id_list = ensure_list(self._archive.keys()) id_list = ensure_list(self._archive.keys())
self._archive.clear() self._archive.clear()
self._path_archive = PersistentMapping() self._path_archive = PersistentMapping()
self._files = PersistentMapping()
for id in id_list: for id in id_list:
self._path_archive[id] = None self._path_archive[id] = None
...@@ -1769,6 +1770,8 @@ class PathTemplateItem(ObjectTemplateItem): ...@@ -1769,6 +1770,8 @@ class PathTemplateItem(ObjectTemplateItem):
obj.wl_clearLocks() obj.wl_clearLocks()
def install(self, context, *args, **kw): def install(self, context, *args, **kw):
for file_name, data in six.iteritems(self._files):
super(PathTemplateItem, self)._importFile(file_name, BytesIO(data))
super(PathTemplateItem, self).install(context, *args, **kw) super(PathTemplateItem, self).install(context, *args, **kw)
# Regenerate local roles for all paths in this business template # Regenerate local roles for all paths in this business template
...@@ -1808,6 +1811,9 @@ class PathTemplateItem(ObjectTemplateItem): ...@@ -1808,6 +1811,9 @@ class PathTemplateItem(ObjectTemplateItem):
% (portal_type, obj.getRelativeUrl())) % (portal_type, obj.getRelativeUrl()))
transaction.get().addBeforeCommitHook(updateLocalRolesOnDocument) transaction.get().addBeforeCommitHook(updateLocalRolesOnDocument)
def _importFile(self, file_name, file_obj):
self._files[file_name] = file_obj.read()
class ToolTemplateItem(PathTemplateItem): class ToolTemplateItem(PathTemplateItem):
"""This class is used only for making a distinction between other objects """This class is used only for making a distinction between other objects
and tools, because tools may not be backed up. and tools, because tools may not be backed up.
......
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