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): ...@@ -675,6 +675,29 @@ class TestDomainTool(TestPredicateMixIn):
tested_base_category_list=['WAAA', 'BOOO'], tested_base_category_list=['WAAA', 'BOOO'],
src__=1)) 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(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
...@@ -1810,14 +1810,19 @@ class Base( CopyContainer, ...@@ -1810,14 +1810,19 @@ class Base( CopyContainer,
# categories # categories
def _setValue(self, id, target, spec=(), filter=None, portal_type=(), keep_default=1, def _setValue(self, id, target, spec=(), filter=None, portal_type=(), keep_default=1,
checked_permission=None): checked_permission=None):
start_string = "%s/" % id getRelativeUrl = self.getPortalObject().portal_url.getRelativeUrl
start_string_len = len(start_string) 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 : if target is None :
path = target path = target
elif isinstance(target, str): elif isinstance(target, str):
# We have been provided a string # We have been provided a string
path = target path = target
if path.startswith(start_string): path = path[start_string_len:] # Prevent duplicating base category
elif isinstance(target, (tuple, list, set, frozenset)): elif isinstance(target, (tuple, list, set, frozenset)):
# We have been provided a list or tuple # We have been provided a list or tuple
path_list = [] path_list = []
...@@ -1825,15 +1830,13 @@ class Base( CopyContainer, ...@@ -1825,15 +1830,13 @@ class Base( CopyContainer,
if isinstance(target_item, str): if isinstance(target_item, str):
path = target_item path = target_item
else: else:
path = target_item.getRelativeUrl() path = getRelativeUrl(target_item)
if path.startswith(start_string): path = path[start_string_len:] # Prevent duplicating base category path_list.append(cleanupCategory(path))
path_list += [path]
path = path_list path = path_list
else: else:
# We have been provided an object # We have been provided an object
# Find the object path = cleanupCategory(getRelativeUrl(target))
path = target.getRelativeUrl()
if path.startswith(start_string): path = path[start_string_len:] # Prevent duplicating base category
self._setCategoryMembership(id, path, spec=spec, filter=filter, portal_type=portal_type, self._setCategoryMembership(id, path, spec=spec, filter=filter, portal_type=portal_type,
base=0, keep_default=keep_default, base=0, keep_default=keep_default,
checked_permission=checked_permission) 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