Commit 6ce5cc01 authored by Yoshinori Okuji's avatar Yoshinori Okuji

RoleTemplateItem.build should generate data consistent with imported data.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33785 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1bbc4001
...@@ -3266,25 +3266,19 @@ class ProductTemplateItem(BaseTemplateItem): ...@@ -3266,25 +3266,19 @@ class ProductTemplateItem(BaseTemplateItem):
class RoleTemplateItem(BaseTemplateItem): class RoleTemplateItem(BaseTemplateItem):
def build(self, context, **kw): def build(self, context, **kw):
role_list = [] for key in self._archive.iterkeys():
for key in self._archive.keys(): self._objects[key] = 1
role_list.append(key)
if len(role_list) > 0:
self._objects[self.__class__.__name__+'/'+'role_list'] = role_list
def preinstall(self, context, installed_item, **kw): def preinstall(self, context, installed_item, **kw):
modified_object_list = {} modified_object_list = {}
if context.getTemplateFormatVersion() == 1: if context.getTemplateFormatVersion() == 1:
new_roles = self._objects.keys() new_roles = self._objects.keys()
if installed_item.id == INSTALLED_BT_FOR_DIFF: # BBB it might be necessary to change the data structure.
#must rename keys in dict if reinstall obsolete_key = self.__class__.__name__ + '/role_list'
new_dict = PersistentMapping() if obsolete_key in installed_item._objects:
old_keys = () for role in installed_item._objects[obsolete_key]:
if len(installed_item._objects.values()) > 0: installed_item._objects[role] = 1
old_keys = installed_item._objects.values()[0] del installed_item._objects[obsolete_key]
for key in old_keys:
new_dict[key] = ''
installed_item._objects = new_dict
for role in new_roles: for role in new_roles:
if installed_item._objects.has_key(role): if installed_item._objects.has_key(role):
continue continue
...@@ -3347,23 +3341,28 @@ class RoleTemplateItem(BaseTemplateItem): ...@@ -3347,23 +3341,28 @@ class RoleTemplateItem(BaseTemplateItem):
p.__ac_roles__ = tuple(roles.keys()) p.__ac_roles__ = tuple(roles.keys())
# Function to generate XML Code Manually # Function to generate XML Code Manually
def generateXml(self, path): def generateXml(self):
obj = self._objects[path] role_list = self._objects.keys()
xml_data = '<role_list>' xml_data = '<role_list>'
obj.sort() for role in sorted(role_list):
for role in obj: xml_data += '\n <role>%s</role>' % (role,)
xml_data += '\n <role>%s</role>' %(role)
xml_data += '\n</role_list>' xml_data += '\n</role_list>'
return xml_data return xml_data
def export(self, context, bta, **kw): def export(self, context, bta, **kw):
if len(self._objects.keys()) == 0: if len(self._objects) == 0:
return return
path = os.path.join(bta.path, self.__class__.__name__) path = os.path.join(bta.path, self.__class__.__name__)
bta.addFolder(name=path) bta.addFolder(name=path)
for path in self._objects.keys(): # BBB it might be necessary to change the data structure.
xml_data = self.generateXml(path=path) obsolete_key = self.__class__.__name__ + '/role_list'
bta.addObject(obj=xml_data, name=path, path=None,) if obsolete_key in self._objects:
for role in self._objects[obsolete_key]:
self._objects[role] = 1
del self._objects[obsolete_key]
xml_data = self.generateXml()
path = obsolete_key
bta.addObject(obj=xml_data, name=path)
class CatalogResultKeyTemplateItem(BaseTemplateItem): class CatalogResultKeyTemplateItem(BaseTemplateItem):
......
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