Commit efe5294e authored by Aurel's avatar Aurel

- rewrite the generateXml method for CatalogMethod and use it to

generate catalog_keys.xml files
- define the preinstall method so that both xml export of catalog
method and catalog_keys files are checked for diff


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@31445 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e431e042
......@@ -2184,32 +2184,12 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
self._filter_type_archive[method_id] = \
catalog.filter_dict[method_id]['type']
def export(self, context, bta, **kw):
def generateXml(self, path):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate, export', 0, 'no SQL catalog was available')
return
if len(self._objects.keys()) == 0:
return
root_path = os.path.join(bta.path, self.__class__.__name__)
for key in self._objects.keys():
obj = self._objects[key]
# create folder and subfolders
folders, id = posixpath.split(key)
path = os.path.join(root_path, folders)
bta.addFolder(name=path)
# export object in xml
f=StringIO()
XMLExportImport.exportXML(obj._p_jar, obj._p_oid, f)
bta.addObject(obj=f.getvalue(), name=id, path=path)
# add all datas specific to catalog inside one file
obj = self._objects[path]
method_id = obj.id
object_path = os.path.join(path, method_id+'.catalog_keys.xml')
f = open(object_path, 'wb')
xml_data = '<catalog_method>'
if self._method_properties.has_key(method_id):
for method_property, value in self._method_properties[method_id].items():
xml_data += '\n <item key="%s" type="int">' %(method_property,)
xml_data += '\n <value>%s</value>' %(value,)
......@@ -2221,7 +2201,11 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
xml_data += '\n <value>1</value>'
xml_data += '\n </item>'
for method in catalog_method_filter_list:
try:
value = getattr(self, method, '')[method_id]
except KeyError:
# the method has no key
continue
if method != '_filter_expression_instance_archive':
if type(value) in (type(''), type(u'')):
xml_data += '\n <item key="%s" type="str">' %(method,)
......@@ -2233,19 +2217,37 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
xml_data += '\n <value>%s</value>' %(str(item))
xml_data += '\n </item>'
xml_data += '\n</catalog_method>'
f.write(xml_data)
f.close()
# Function to generate XML Code Manually
def generateXml(self, path=None):
obj = self._objects[path]
xml_data = '<key_list>'
obj.sort()
for key in obj:
xml_data += '\n <key>%s</key>' %(key)
xml_data += '\n</key_list>'
return xml_data
def preinstall(self, context, installed_bt, **kw):
modified_object_dict = ObjectTemplateItem.preinstall(self, context, installed_bt, **kw)
modified_object_dict.update(BaseTemplateItem.preinstall(self, context, installed_bt, **kw))
return modified_object_dict
def export(self, context, bta, **kw):
catalog = _getCatalogValue(self)
if catalog is None:
LOG('BusinessTemplate, export', 0, 'no SQL catalog was available')
return
if len(self._objects.keys()) == 0:
return
root_path = os.path.join(bta.path, self.__class__.__name__)
for key in self._objects.keys():
obj = self._objects[key]
# create folder and subfolders
folders, id = posixpath.split(key)
path = os.path.join(root_path, folders)
bta.addFolder(name=path)
# export object in xml
f=StringIO()
XMLExportImport.exportXML(obj._p_jar, obj._p_oid, f)
bta.addObject(obj=f.getvalue(), name=id, path=path)
# add all datas specific to catalog inside one file
key_name = os.path.join(obj.id+'.catalog_keys')
xml_data = self.generateXml(key)
bta.addObject(obj=xml_data, name=key_name, path=path)
def install(self, context, trashbin, **kw):
ObjectTemplateItem.install(self, context, trashbin, **kw)
catalog = _getCatalogValue(self)
......
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