Commit d9fb5f69 authored by Jérome Perrin's avatar Jérome Perrin

Support domains in category accessors

parent 660662f4
......@@ -675,6 +675,29 @@ class TestDomainTool(TestPredicateMixIn):
tested_base_category_list=['WAAA', 'BOOO'],
src__=1))
def test_setRelationToBaseDomain(self):
# category accessors can be useed to set relations to base domains.
base_domain = self.portal.portal_domains.newContent(
portal_type='Base Domain')
# get a document with source accessor
document = self.portal.sale_order_module.newContent(
portal_type='Sale Order')
document.setSourceValue(base_domain)
self.assertEqual(base_domain, document.getSourceValue())
def test_setRelationToDomain(self):
# category accessors can be useed to set relations to domains.
base_domain = self.portal.portal_domains.newContent(
portal_type='Base Domain')
domain = base_domain.newContent(portal_type='Domain')
# get a document with source accessor
document = self.portal.sale_order_module.newContent(
portal_type='Sale Order')
document.setSourceValue(domain)
self.assertEqual(domain, document.getSourceValue())
def test_suite():
suite = unittest.TestSuite()
......
......@@ -1810,14 +1810,19 @@ class Base( CopyContainer,
# categories
def _setValue(self, id, target, spec=(), filter=None, portal_type=(), keep_default=1,
checked_permission=None):
start_string = "%s/" % id
start_string_len = len(start_string)
getRelativeUrl = self.getPortalObject().portal_url.getRelativeUrl
def cleanupCategory(path):
# prevent duplicating base categories and storing "portal_categories/"
for start_string in ("%s/" % id, "portal_categories/"):
if path.startswith(start_string):
path = path[len(start_string):]
return path
if target is None :
path = target
elif isinstance(target, str):
# We have been provided a string
path = target
if path.startswith(start_string): path = path[start_string_len:] # Prevent duplicating base category
elif isinstance(target, (tuple, list, set, frozenset)):
# We have been provided a list or tuple
path_list = []
......@@ -1825,15 +1830,13 @@ class Base( CopyContainer,
if isinstance(target_item, str):
path = target_item
else:
path = target_item.getRelativeUrl()
if path.startswith(start_string): path = path[start_string_len:] # Prevent duplicating base category
path_list += [path]
path = getRelativeUrl(target_item)
path_list.append(cleanupCategory(path))
path = path_list
else:
# We have been provided an object
# Find the object
path = target.getRelativeUrl()
if path.startswith(start_string): path = path[start_string_len:] # Prevent duplicating base category
path = cleanupCategory(getRelativeUrl(target))
self._setCategoryMembership(id, path, spec=spec, filter=filter, portal_type=portal_type,
base=0, keep_default=keep_default,
checked_permission=checked_permission)
......
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