Commit 64f4635c authored by Nicolas Wavrant's avatar Nicolas Wavrant Committed by Ayush Tiwari

BusinessTemplate: any single property of any object can be save in a bt5

It is useful to save some customizations, preferences, or eve additions for test business templates
This feature is managed by a new class: ObjectPropertyTemplateItem
parent 8a162e24
...@@ -4948,6 +4948,80 @@ class LocalRolesTemplateItem(BaseTemplateItem): ...@@ -4948,6 +4948,80 @@ class LocalRolesTemplateItem(BaseTemplateItem):
delattr(obj, '__ac_local_roles_group_id_dict__') delattr(obj, '__ac_local_roles_group_id_dict__')
obj.reindexObject() obj.reindexObject()
class ObjectPropertyTemplateItem(BaseTemplateItem):
xml_tag = "object_property_list"
def build(self, context, **kw):
p = context.getPortalObject()
for key in self._archive:
relative_url, property_name = key.split(' | ')
property_value = p.unrestrictedTraverse(relative_url) \
.getProperty(property_name)
self._objects.setdefault(relative_url, {})[property_name] = property_value
def generateXml(self, path=None):
xml_data = '<%s>' % self.xml_tag
for relative_url in self._objects:
xml_data += '\n <object relative_url="%s">' % relative_url
for property_name, property_value in self._objects[relative_url].iteritems():
xml_data += '\n <property name="%s">' % property_name.replace('_list', '')
if property_name.endswith('_list'):
for value in property_value:
xml_data += '\n <item>%s</item>' % value
else:
xml_data += '\n <item>%s</item>' % property_value
xml_data += '\n </property>'
xml_data += '\n </object>'
xml_data += '\n</%s>' % self.xml_tag
return xml_data
def export(self, context, bta, **kw):
path = self.__class__.__name__
if self._objects.keys():
xml_data = self.generateXml()
bta.addObject(xml_data, name=self.xml_tag, path=path)
def _importFile(self, file_name, file):
if not file_name.endswith('.xml'):
LOG('Business Template', 0, 'Skipping file "%s"' % (file_name, ))
return
xml = parse(file)
object_list = xml.findall('object')
for obj in object_list:
for obj_property in obj.findall('property'):
item_list = []
for item in obj_property.findall('item'):
item_list.append(item.text)
property_name = obj_property.get('name') + ('' if len(item_list) <= 1 else '_list')
self._objects[obj.get('relative_url')] = {property_name: item_list}
def preinstall(self, context, installed_item, **kw):
modified_object_list = {}
for relative_url in self._objects:
new_object = self._objects[relative_url]
try:
old_object = installed_item._objects[relative_url]
except KeyError:
modified_object_list.update({relative_url : ['New', self.__class__.__name__[:-12]]})
else:
modified_object_list.update({relative_url : ['Modified', self.__class__.__name__[:-12]]})
return modified_object_list
def install(self, context, trashbin, **kw):
portal = context.getPortalObject()
for relative_url in self._objects:
obj = portal.unrestrictedTraverse(relative_url)
for property_name, property_value in self._objects[relative_url].iteritems():
obj.setProperty(property_name, property_value)
def uninstall(self, context, **kw):
portal = context.getPortalObject()
for relative_url in self._objects:
obj = portal.unrestrictedTraverse(relative_url)
for property_name in self._objects[relative_url]:
obj.setProperty(property_name, None)
class bt(dict): class bt(dict):
"""Fake 'bt' item to read bt/* files through BusinessTemplateArchive""" """Fake 'bt' item to read bt/* files through BusinessTemplateArchive"""
...@@ -5183,6 +5257,8 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -5183,6 +5257,8 @@ Business Template is a set of definitions, such as skins, portal types and categ
self._catalog_local_role_key_item = \ self._catalog_local_role_key_item = \
CatalogLocalRoleKeyTemplateItem( CatalogLocalRoleKeyTemplateItem(
self.getTemplateCatalogLocalRoleKeyList()) self.getTemplateCatalogLocalRoleKeyList())
self._object_property_item = \
ObjectPropertyTemplateItem(self.getTemplateObjectPropertyList())
try: try:
self._catalog_security_uid_column_item = \ self._catalog_security_uid_column_item = \
CatalogSecurityUidColumnTemplateItem( CatalogSecurityUidColumnTemplateItem(
...@@ -5964,6 +6040,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -5964,6 +6040,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
'CatalogRoleKey' : '_catalog_role_key_item', 'CatalogRoleKey' : '_catalog_role_key_item',
'CatalogLocalRoleKey' : '_catalog_local_role_key_item', 'CatalogLocalRoleKey' : '_catalog_local_role_key_item',
'CatalogSecurityUidColumn' : '_catalog_security_uid_column_item', 'CatalogSecurityUidColumn' : '_catalog_security_uid_column_item',
'ObjectProperty': '_object_property_item',
} }
object_id = REQUEST.object_id object_id = REQUEST.object_id
...@@ -6033,7 +6110,8 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -6033,7 +6110,8 @@ Business Template is a set of definitions, such as skins, portal types and categ
'_portal_type_roles_item', '_portal_type_roles_item',
'_portal_type_base_category_item', '_portal_type_base_category_item',
'_local_roles_item', '_local_roles_item',
'_portal_type_workflow_chain_item',] '_portal_type_workflow_chain_item',
'_object_property_item',]
# Text objects (no need to export them into XML) # Text objects (no need to export them into XML)
# XXX Bad naming # XXX Bad naming
......
...@@ -96,6 +96,7 @@ item_name_list = ( ...@@ -96,6 +96,7 @@ item_name_list = (
'catalog_role_key', 'catalog_role_key',
'catalog_local_role_key', 'catalog_local_role_key',
'catalog_security_uid_column', 'catalog_security_uid_column',
'object_property',
) )
item_set = set(('CatalogDateTimeKey' if x == 'catalog_datetime_key' else item_set = set(('CatalogDateTimeKey' if x == 'catalog_datetime_key' else
......
...@@ -83,6 +83,7 @@ ...@@ -83,6 +83,7 @@
<string>my_template_constraint_id_list</string> <string>my_template_constraint_id_list</string>
<string>my_template_local_role_list</string> <string>my_template_local_role_list</string>
<string>my_template_portal_type_role_list</string> <string>my_template_portal_type_role_list</string>
<string>my_template_object_property_list</string>
</list> </list>
</value> </value>
</item> </item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Standard Property" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_local_properties</string> </key>
<value>
<tuple>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>mode</string> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>string</string> </value>
</item>
</dictionary>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>elementary_type/lines</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>A list of base categories for portal types</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>template_object_property_property</string> </value>
</item>
<item>
<key> <string>mode</string> </key>
<value> <string>w</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Standard Property</string> </value>
</item>
<item>
<key> <string>property_default</string> </key>
<value> <string>python: ()</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -7556,6 +7556,63 @@ class TestBusinessTemplate(BusinessTemplateMixin): ...@@ -7556,6 +7556,63 @@ class TestBusinessTemplate(BusinessTemplateMixin):
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self) sequence_list.play(self)
def stepSetPropertyOnModule(self, sequence=None, **kw):
module_id = sequence.get('module_id')
module = self.getPortalObject()[module_id]
for name, value in self.object_property_dict.iteritems():
module.setProperty(name, value)
def stepAddModulePropertyToBusinessTemplate(self, sequence=None, **kw):
module_id = sequence.get('module_id')
bt_object_property_list = []
for property_name, _ in self.object_property_dict.iteritems():
bt_object_property_list.append("%s | %s" % (module_id, property_name))
bt = sequence.get('export_bt')
bt.edit(template_object_property_list=bt_object_property_list)
def stepCheckModuleProperty(self, sequence=None, **kw):
module_id = sequence.get('module_id')
module = self.getPortalObject()[module_id]
for name, value in self.object_property_dict.iteritems():
self.assertEqual(module.getProperty(name), value)
def stepCheckModulePropertyIsNone(self, sequence=None, **kw):
module_id = sequence.get('module_id')
module = self.getPortalObject()[module_id]
for property_name, _ in self.object_property_dict.iteritems():
self.assertEqual(module.getProperty(property_name), None)
test_object_property_string = """
CreatePortalType
CreateModuleAndObjects
stepSetPropertyOnModule
CheckModuleProperty
CreateNewBusinessTemplate
UseExportBusinessTemplate
AddModulePropertyToBusinessTemplate
BuildBusinessTemplate
CheckBuiltBuildingState
SaveBusinessTemplate
RemoveModule
CreateModuleAndObjects
CheckModulePropertyIsNone
UseExportBusinessTemplate
stepInstallCurrentBusinessTemplate
CheckModuleProperty
"""
def test_ExportAndImportObjectProperty(self):
sequence = Sequence()
self.object_property_dict = {'business_application': 'base'}
sequence.setSequenceString(self.test_object_property_string)
sequence.play(self)
# Same test as before, but with a category_list property
def test_ExportAndImportObjectPropertyList(self):
sequence = Sequence()
self.object_property_dict = {'business_application_list': ('base', 'extended')}
sequence.setSequenceString(self.test_object_property_string)
sequence.play(self)
from Products.ERP5Type.Core.DocumentComponent import DocumentComponent from Products.ERP5Type.Core.DocumentComponent import DocumentComponent
......
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