bt5: refactoring begin: remove ObjectTemplateItem.preinstall add BaseTemplateItem.generateXml diff -r 512b9c7b1978 products/ERP5/Document/BusinessTemplate.py --- a/products/ERP5/Document/BusinessTemplate.py Thu Sep 18 14:47:58 2008 +0400 +++ b/products/ERP5/Document/BusinessTemplate.py Thu Sep 18 17:28:43 2008 +0400 @@ -380,9 +380,9 @@ new_keys = self._objects.keys() for path in new_keys: if installed_bt._objects.has_key(path): - # compare objects to see it there are changes + # compare object to see if there are differences new_obj_xml = self.generateXml(path=path) - old_obj_xml = installed_bt.generateXml(path=path) + old_obj_xml = installed_bt.generateXml(path=path, remove_properties=True) if new_obj_xml != old_obj_xml: modified_object_list.update({path : ['Modified', self.__class__.__name__[:-12]]}) # else, compared versions are identical, don't overwrite the old one @@ -608,36 +608,15 @@ self.removeProperties(obj) self._objects[file_name[:-4]] = obj - def preinstall(self, context, installed_bt, **kw): - #XXX -12 used here is -len('TemplateItem') - modified_object_list = {} - if context.getTemplateFormatVersion() == 1: - portal = context.getPortalObject() - new_keys = self._objects.keys() - for path in new_keys: - if installed_bt._objects.has_key(path): - # compare object to see it there is changes - new_object = self._objects[path] - old_object = installed_bt._objects[path] - old_object = self.removeProperties(old_object) - new_io = StringIO() - old_io = StringIO() - OFS.XMLExportImport.exportXML(new_object._p_jar, new_object._p_oid, new_io) - OFS.XMLExportImport.exportXML(old_object._p_jar, old_object._p_oid, old_io) - new_obj_xml = new_io.getvalue() - old_obj_xml = old_io.getvalue() - new_io.close() - old_io.close() - if new_obj_xml != old_obj_xml: - modified_object_list.update({path : ['Modified', self.__class__.__name__[:-12]]}) - else: # new object - modified_object_list.update({path : ['New', self.__class__.__name__[:-12]]}) - # get removed object - old_keys = installed_bt._objects.keys() - for path in old_keys: - if path not in new_keys: - modified_object_list.update({path : ['Removed', self.__class__.__name__[:-12]]}) - return modified_object_list + def generateXml(self, path, remove_properties=False, **kw): + obj = self._objects[path] + if kw.get('remove_properties'): + obj = self.removeProperties(obj) + io = StringIO() + OFS.XMLExportImport.exportXML(obj._p_jar, obj._p_oid, io) + obj_xml = io.getvalue() + io.close() + return obj_xml def _backupObject(self, action, trashbin, container_path, object_id, **kw): """ @@ -1292,29 +1271,22 @@ return ObjectTemplateItem.__init__(self, id_list, tool_id=tool_id, **kw) def preinstall(self, context, installed_bt, **kw): - modified_object_list = {} - if context.getTemplateFormatVersion() == 1: - portal = context.getPortalObject() - new_keys = self._objects.keys() - for path in new_keys: - if installed_bt._objects.has_key(path): - # compare object to see it there is changes - new_object = self._objects[path] - old_object = installed_bt._objects[path] - new_io = StringIO() - old_io = StringIO() - OFS.XMLExportImport.exportXML(new_object._p_jar, new_object._p_oid, new_io) - OFS.XMLExportImport.exportXML(old_object._p_jar, old_object._p_oid, old_io) - new_obj_xml = new_io.getvalue() - old_obj_xml = old_io.getvalue() - new_io.close() - old_io.close() + #XXX this method cut and paste BaseTemplateItem.preinstall + # one diffrerence path in Modified + modified_object_list = {} + if context.getTemplateFormatVersion() == 1: + new_keys = self._objects.keys() + for path in new_keys: + if installed_bt._objects.has_key(path): + # compare object to see if there are differences + new_obj_xml = self.generateXml(path=path) + old_obj_xml = installed_bt.generateXml(path=path) if new_obj_xml != old_obj_xml: wf_id = path.split('/')[:2] modified_object_list.update({'/'.join(wf_id) : ['Modified', 'Workflow']}) else: # new object modified_object_list.update({path : ['New', 'Workflow']}) - # get removed object + # list removed objects old_keys = installed_bt._objects.keys() for path in old_keys: if path not in new_keys: @@ -1487,7 +1459,7 @@ % portal_type # Function to generate XML Code Manually - def generateXml(self, path=None): + def generateXml(self, path=None, **kw): xml_data = '' keys = self._objects.keys() keys.sort() @@ -1686,7 +1658,7 @@ self._objects[portal_type] = [allowed_type] # Function to generate XML Code Manually - def generateXml(self, path=None): + def generateXml(self, path=None, **kw): dictio = self._objects xml_data = '<%s>' %(self.xml_tag,) keys = dictio.keys() @@ -2332,7 +2304,7 @@ self._objects[relative_url] = type_role_list # Function to generate XML Code Manually - def generateXml(self, path=None): + def generateXml(self, path=None, **kw): type_role_list = self._objects[path] xml_data = '' for role in type_role_list: @@ -2513,7 +2485,7 @@ BaseTemplateItem.uninstall(self, context, **kw) # Function to generate XML Code Manually - def generateXml(self, path=None): + def generateXml(self, path=None, **kw): xml_data = '' prop_type, obj = self._objects[path] xml_data += '\n ' @@ -2560,7 +2532,7 @@ self._objects[id] = dict # Function to generate XML Code Manually - def generateXml(self, path=None): + def generateXml(self, path=None, **kw): dict = self._objects[path] xml_data = '' # sort key @@ -2915,7 +2887,7 @@ p.__ac_roles__ = tuple(roles.keys()) # Function to generate XML Code Manually - def generateXml(self, path): + def generateXml(self, path, **kw): obj = self._objects[path] xml_data = '' obj.sort() @@ -3006,7 +2978,7 @@ BaseTemplateItem.uninstall(self, context, **kw) # Function to generate XML Code Manually - def generateXml(self, path=None): + def generateXml(self, path=None, **kw): obj = self._objects[path] xml_data = '' obj.sort() @@ -3100,7 +3072,7 @@ BaseTemplateItem.uninstall(self, context, **kw) # Function to generate XML Code Manually - def generateXml(self, path=None): + def generateXml(self, path=None, **kw): obj = self._objects[path] xml_data = '' obj.sort() @@ -3191,7 +3163,7 @@ BaseTemplateItem.uninstall(self, context, **kw) # Function to generate XML Code Manually - def generateXml(self, path=None): + def generateXml(self, path=None, **kw): obj = self._objects[path] xml_data = '' obj.sort() @@ -3283,7 +3255,7 @@ BaseTemplateItem.uninstall(self, context, **kw) # Function to generate XML Code Manually - def generateXml(self, path=None): + def generateXml(self, path=None, **kw): obj = self._objects[path] xml_data = '' obj.sort() @@ -3375,7 +3347,7 @@ BaseTemplateItem.uninstall(self, context, **kw) # Function to generate XML Code Manually - def generateXml(self, path=None): + def generateXml(self, path=None, **kw): obj = self._objects[path] xml_data = '' obj.sort() @@ -3467,7 +3439,7 @@ BaseTemplateItem.uninstall(self, context, **kw) # Function to generate XML Code Manually - def generateXml(self, path=None): + def generateXml(self, path=None, **kw): obj = self._objects[path] xml_data = '' obj.sort() @@ -3560,7 +3532,7 @@ BaseTemplateItem.uninstall(self, context, **kw) # Function to generate XML Code Manually - def generateXml(self, path=None): + def generateXml(self, path=None, **kw): obj = self._objects[path] xml_data = '' obj.sort() @@ -3651,7 +3623,7 @@ BaseTemplateItem.uninstall(self, context, **kw) # Function to generate XML Code Manually - def generateXml(self, path=None): + def generateXml(self, path=None, **kw): obj = self._objects[path] xml_data = '' obj.sort() @@ -3743,7 +3715,7 @@ BaseTemplateItem.uninstall(self, context, **kw) # Function to generate XML Code Manually - def generateXml(self, path=None): + def generateXml(self, path=None, **kw): obj = self._objects[path] xml_data = '' obj.sort() @@ -3835,7 +3807,7 @@ BaseTemplateItem.uninstall(self, context, **kw) # Function to generate XML Code Manually - def generateXml(self, path=None): + def generateXml(self, path=None, **kw): obj = self._objects[path] xml_data = '' obj.sort() @@ -3928,7 +3900,7 @@ BaseTemplateItem.uninstall(self, context, **kw) # Function to generate XML Code Manually - def generateXml(self, path=None): + def generateXml(self, path=None, **kw): obj = self._objects[path] xml_data = '' obj.sort() @@ -4021,7 +3993,7 @@ BaseTemplateItem.uninstall(self, context, **kw) # Function to generate XML Code Manually - def generateXml(self, path=None): + def generateXml(self, path=None, **kw): obj = self._objects[path] xml_data = '' obj.sort() @@ -4143,7 +4115,7 @@ self._objects[path] = (local_roles_dict, group_local_roles_dict) # Function to generate XML Code Manually - def generateXml(self, path=None): + def generateXml(self, path=None, **kw): local_roles_dict, group_local_roles_dict = self._objects[path] local_roles_keys = local_roles_dict.keys() group_local_roles_keys = group_local_roles_dict.keys()