Commit 4042ea2d authored by Yoshinori Okuji's avatar Yoshinori Okuji

Fix the export of site properties. Change the behavior of the installation to...

Fix the export of site properties. Change the behavior of the installation to overwrite site properties, even if the same properties already exist.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21085 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8aa927b4
...@@ -70,6 +70,7 @@ from warnings import warn ...@@ -70,6 +70,7 @@ from warnings import warn
from OFS.ObjectManager import customImporters from OFS.ObjectManager import customImporters
from gzip import GzipFile from gzip import GzipFile
from xml.dom.minidom import parse from xml.dom.minidom import parse
from xml.sax.saxutils import escape
from Products.CMFCore.Expression import Expression from Products.CMFCore.Expression import Expression
import tarfile import tarfile
from urllib import quote, unquote from urllib import quote, unquote
...@@ -2510,20 +2511,28 @@ class SitePropertyTemplateItem(BaseTemplateItem): ...@@ -2510,20 +2511,28 @@ class SitePropertyTemplateItem(BaseTemplateItem):
if action == 'nothing': if action == 'nothing':
continue continue
dir, id = posixpath.split(path) dir, id = posixpath.split(path)
if p.hasProperty(id):
continue
prop_type, property = self._objects[path] prop_type, property = self._objects[path]
p._setProperty(id, property, type=prop_type) if p.hasProperty(id):
if p.getPropertyType(id) != prop_type:
p._delProperty(id)
p._setProperty(id, property, type=prop_type)
else:
p._updateProperty(id, property)
else:
p._setProperty(id, property, type=prop_type)
else: else:
BaseTemplateItem.install(self, context, trashbin, **kw) BaseTemplateItem.install(self, context, trashbin, **kw)
p = context.getPortalObject() p = context.getPortalObject()
for id,property in self._archive.keys(): for id, property in self._archive.keys():
property = self._archive[id] property = self._archive[id]
if p.hasProperty(id): if p.hasProperty(id):
continue if p.getPropertyType(id) != property['type']:
# Too much??? p._delProperty(id)
#raise TemplateConflictError, 'the property %s already exists' % id p._setProperty(id, property['value'], type=property['type'])
p._setProperty(id, property['value'], type=property['type']) else:
p._updateProperty(id, property['value'])
else:
p._setProperty(id, property['value'], type=property['type'])
def uninstall(self, context, **kw): def uninstall(self, context, **kw):
p = context.getPortalObject() p = context.getPortalObject()
...@@ -2542,16 +2551,16 @@ class SitePropertyTemplateItem(BaseTemplateItem): ...@@ -2542,16 +2551,16 @@ class SitePropertyTemplateItem(BaseTemplateItem):
xml_data = '' xml_data = ''
prop_type, obj = self._objects[path] prop_type, obj = self._objects[path]
xml_data += '\n <property>' xml_data += '\n <property>'
xml_data += '\n <id>%s</id>' %(path,) xml_data += '\n <id>%s</id>' % escape(str(path))
xml_data += '\n <type>%s</type>' %(prop_type,) xml_data += '\n <type>%s</type>' % escape(str(prop_type))
if prop_type in ('lines', 'tokens'): if prop_type in ('lines', 'tokens'):
xml_data += '\n <value>' xml_data += '\n <value>'
for item in obj: for item in obj:
if item != '': if item != '':
xml_data += '\n <item>%s</item>' %(item,) xml_data += '\n <item>%s</item>' % escape(str(item))
xml_data += '\n </value>' xml_data += '\n </value>'
else: else:
xml_data += '\n <value>%r</value>' %(('\n').join(obj),) xml_data += '\n <value>%s</value>' % escape(str(obj))
xml_data += '\n </property>' xml_data += '\n </property>'
return xml_data return xml_data
......
...@@ -5024,6 +5024,86 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor): ...@@ -5024,6 +5024,86 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
sequence_list.play(self, quiet=quiet) sequence_list.play(self, quiet=quiet)
def stepSetOldSitePropertyValue(self, sequence=None, sequence_list=None, **kw):
"""Set the old value to a site property."""
sequence.set('site_property_value', 'old')
def stepSetNewSitePropertyValue(self, sequence=None, sequence_list=None, **kw):
"""Set the new value to a site property."""
sequence.set('site_property_value', 'new')
def stepCreateSiteProperty(self, sequence=None, sequence_list=None, **kw):
"""Create a site property."""
portal = self.getPortal()
portal._setProperty('a_property', sequence.get('site_property_value'))
def stepModifySiteProperty(self, sequence=None, sequence_list=None, **kw):
"""Modify a site property."""
portal = self.getPortal()
portal._updateProperty('a_property', sequence.get('site_property_value'))
def stepCheckSiteProperty(self, sequence=None, sequence_list=None, **kw):
"""Check a site property."""
portal = self.getPortal()
self.assertEquals(portal.getProperty('a_property'),
sequence.get('site_property_value'))
def stepCheckSitePropertyRemoved(self, sequence=None, sequence_list=None, **kw):
"""Check if a site property is removed."""
portal = self.getPortal()
self.failIf(portal.hasProperty('a_property'))
def stepAddSitePropertyToBusinessTemplate(self, sequence=None, sequence_list=None,
**kw):
"""Add a site property into a business template."""
bt = sequence.get('current_bt', None)
self.failUnless(bt is not None)
bt.edit(template_site_property_id_list=('a_property',))
def test_39_CheckSiteProperties(self, quiet=quiet, run=run_all_test):
if not run: return
if not quiet:
message = 'Test Site Properties'
ZopeTestCase._print('\n%s ' % message)
LOG('Testing... ', 0, message)
sequence_list = SequenceList()
sequence_string = '\
SetOldSitePropertyValue \
CreateSiteProperty \
CreateNewBusinessTemplate \
UseExportBusinessTemplate \
CheckModifiedBuildingState \
CheckNotInstalledInstallationState \
AddSitePropertyToBusinessTemplate \
BuildBusinessTemplate \
CheckBuiltBuildingState \
CheckNotInstalledInstallationState \
SaveBusinessTemplate \
CheckBuiltBuildingState \
CheckNotInstalledInstallationState \
RemoveBusinessTemplate \
RemoveAllTrashBins \
SetNewSitePropertyValue \
ModifySiteProperty \
ImportBusinessTemplate \
UseImportBusinessTemplate \
CheckBuiltBuildingState \
CheckNotInstalledInstallationState \
InstallBusinessTemplate \
Tic \
CheckInstalledInstallationState \
CheckBuiltBuildingState \
SetOldSitePropertyValue \
CheckSiteProperty \
UninstallBusinessTemplate \
CheckBuiltBuildingState \
CheckNotInstalledInstallationState \
SetOldSitePropertyValue \
CheckSitePropertyRemoved \
'
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self, quiet=quiet)
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestBusinessTemplate)) suite.addTest(unittest.makeSuite(TestBusinessTemplate))
......
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