Commit ee1a4d70 authored by Julien Muchembled's avatar Julien Muchembled

BusinessTemplate: remove dead code

This reverts most fixes to r28422. They are not useful anymore since objects
are not modified anymore during download.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38633 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 06a327f0
......@@ -4852,42 +4852,22 @@ Business Template is a set of definitions, such as skins, portal types and categ
# Create temporary modules/classes for classes defined by this BT.
# This is required if the BT contains instances of one of these classes.
orig_module_dict = {}
instance_oid_list = []
module_id_list = []
for template_id in self.getTemplateDocumentIdList():
module_id = 'Products.ERP5Type.Document.' + template_id
orig_module_dict[module_id] = sys.modules.get(module_id)
# Always redefine the module, so that 'instance_oid_list' contains
# the full list of oid to remove from pickle cache.
module_id = 'Products.ERP5Type.Document.' + template_id
if module_id not in sys.modules:
module_id_list.append(module_id)
sys.modules[module_id] = module = imp.new_module(module_id)
module.SimpleItem = SimpleItem.SimpleItem
module.instance_oid_list = instance_oid_list
exec """class %s(SimpleItem):
def __setstate__(self, state):
instance_oid_list.append(self._p_oid)
return SimpleItem.__setstate__(self, state)""" % template_id \
in module.__dict__
setattr(module, template_id, type(template_id,
(SimpleItem.SimpleItem,), {'__module__': module_id}))
for item_name in self._item_name_list:
getattr(self, item_name).importFile(bta)
if instance_oid_list:
# If a temporary class was used, we must force all instances using it
# to be reloaded (i.e. unpickle) on next access (at installation).
# Doing a savepoint will pickle them to a temporary storage so that all
# references to it can be freed.
transaction.savepoint(optimistic=True)
self._p_jar.cacheMinimize()
gc.collect()
# Remove temporary modules created above to allow import of real modules
# (during the installation).
# Restore original module if any, in case the new one is not installed.
for module_id, module in orig_module_dict.iteritems():
if module is None:
del sys.modules[module_id]
else:
sys.modules[module_id] = module
for module_id in module_id_list:
del sys.modules[module_id]
def getItemsList(self):
"""Return list of items in business template
......
......@@ -6630,12 +6630,15 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
sequence_list.play(self, quiet=quiet)
def test_167_InstanceAndRelatedClassDefinedInSameBT(self):
# This test does too much since we don't modify objects anymore during
# download. Objects are cleaned up during installation, which does not
# require any specific action about garbage collection or pickle cache.
from Products.ERP5Type.Document.BusinessTemplate import BaseTemplateItem
portal = self.portal
BaseTemplateItem_removeProperties = BaseTemplateItem.removeProperties
marker_list = []
def removeProperties(self, obj, export):
# Check it works if the object is modified during download.
# Check it works if the object is modified during install.
obj.int_index = marker_list.pop()
return obj
SimpleItem_getCopy = SimpleItem._getCopy
......@@ -6655,15 +6658,16 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
del self.logged[:]
# check its class has not yet been overriden
self.assertFalse(getattr(portal.another_file, 'isClassOverriden', False))
for i in xrange(6):
for i in (0, 1):
marker_list.append(i)
gc.disable()
bt = template_tool.download(bt_path)
assert not marker_list
if i in (2, 4, 5):
assert marker_list
if i:
transaction.commit()
self.tic()
bt.install(force=1)
assert not marker_list
gc.enable()
self.assertEqual(portal.some_file.int_index, i)
transaction.commit()
......
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