Commit 832970fc authored by Arnaud Fontaine's avatar Arnaud Fontaine

Allow to reset components upon modification.

For now this is a global reset, meaning that everytime a component is changed,
all the component are reset, which is terrible from a performance point of
view.
parent c89c6533
...@@ -58,6 +58,22 @@ class DocumentComponent(Base): ...@@ -58,6 +58,22 @@ class DocumentComponent(Base):
'Reference', 'Reference',
'TextDocument') 'TextDocument')
# XXX-arnau: per-component reset, global for now
# def reset(self):
# import erp5
#
# try:
# component_namespace_name, module_name = self.getId().split('.')[1:]
# component_namespace = getattr(erp5, component_namespace_name)
# except (ValueError, AttributeError):
# LOG("ERP5Type.Core.DocumentComponent", DEBUG,
# "Invalid namespace %s..." % self.getId())
# else:
# if module_name in component_namespace.__dict__:
# LOG("ERP5Type.Core.DocumentComponent", INFO, "Reset %s..." % self.getId())
# getattr(component_namespace, module_name).restoreGhostState()
def load(self): def load(self):
# XXX-arnau: There should be a load_source() taking a string rather than # XXX-arnau: There should be a load_source() taking a string rather than
# creating a temporary file # creating a temporary file
......
...@@ -31,6 +31,8 @@ from AccessControl import ClassSecurityInfo ...@@ -31,6 +31,8 @@ from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Tool.BaseTool import BaseTool from Products.ERP5Type.Tool.BaseTool import BaseTool
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from zLOG import LOG, INFO
class ComponentTool(BaseTool): class ComponentTool(BaseTool):
""" """
This tool provides methods to load the the different types This tool provides methods to load the the different types
...@@ -43,3 +45,28 @@ class ComponentTool(BaseTool): ...@@ -43,3 +45,28 @@ class ComponentTool(BaseTool):
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
def reset(self):
"""
XXX-arnau: global reset
"""
import erp5.component
container_type_info = self.getPortalObject().portal_types.getTypeInfo(
self.getPortalType())
for content_type in container_type_info.getTypeAllowedContentTypeList():
module_name = content_type.split(' ')[0].lower()
try:
module = getattr(erp5.component, module_name)
# XXX-arnau: not everything is defined yet...
except AttributeError:
pass
else:
for name in module.__dict__.keys():
if name[0] != '_':
LOG("ERP5Type.Tool.ComponentTool", INFO,
"Global reset of %s.%s" % (module_name, name))
delattr(module, name)
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