Commit 4aa1b35a authored by Julien Muchembled's avatar Julien Muchembled

Make Category.SetSetter accept sets and use sets to remove duplicates

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34559 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b0b535c8
......@@ -106,19 +106,14 @@ class SetSetter(BaseSetter):
self.__name__ = id
self._key = key
def __call__(self, instance, *args, **kw):
def __call__(self, instance, value, *args, **kw):
"""
We should take care that the provided argument has no
duplicate values
"""
if type(args[0]) in (type([]),type(())):
new_list = []
for item in args[0]:
if item not in new_list:
new_list.append(item)
else:
new_list = args[0]
instance._setCategoryMembership(self._key, new_list,
if type(value) not in (set, frozenset):
value = frozenset(value)
instance._setCategoryMembership(self._key, tuple(value),
spec=kw.get('spec',()),
filter=kw.get('filter', None),
portal_type=kw.get('portal_type',()),
......
......@@ -711,30 +711,25 @@ class TestPropertySheet:
self.assertEquals(person.getRegion(), 'alpha')
person.setRegionList(['alpha', 'alpha'])
self.assertEquals(person.getRegionList(), ['alpha', 'alpha'])
person.setRegionSet(['alpha', 'alpha'])
self.assertEquals(person.getRegionSet(), ['alpha'])
person.setRegionList(['alpha', 'beta', 'alpha'])
self.assertEquals(person.getRegionList(), ['alpha', 'beta', 'alpha'])
person.setRegionSet(['beta', 'alpha', 'alpha'])
self.assertEquals(person.getRegionList(), ['alpha', 'beta'])
person.setRegionList(['beta', 'alpha', 'alpha'])
self.assertEquals(person.getRegionList(), ['beta', 'alpha', 'alpha'])
person.setRegionSet(['alpha', 'beta', 'alpha'])
result = person.getRegionSet()
result.sort()
self.assertEquals(result, ['alpha', 'beta'])
person.setDefaultRegion('beta')
self.assertEquals(person.getDefaultRegion(), 'beta')
result = person.getRegionSet()
result.sort()
self.assertEquals(result, ['alpha', 'beta'])
self.assertEquals(person.getRegionList(), ['beta', 'alpha'])
person.setDefaultRegion('alpha')
self.assertEquals(person.getDefaultRegion(), 'alpha')
result = person.getRegionSet()
result.sort()
self.assertEquals(result, ['alpha', 'beta'])
self.assertEquals(sorted(person.getRegionSet()), ['alpha', 'beta'])
self.assertEquals(person.getRegionList(), ['alpha', 'beta'])
person.setDefaultRegion('beta')
self.assertEquals(person.getDefaultRegion(), 'beta')
self.assertEquals(sorted(person.getRegionSet()), ['alpha', 'beta'])
self.assertEquals(person.getRegionList(), ['beta', 'alpha'])
# Test accessor on documents rather than on categories
person.setDefaultRegion(person.getRelativeUrl())
self.assertEquals(person.getDefaultRegion(), person.getRelativeUrl())
self.assertEquals(person.getRegionList(), [person.getRelativeUrl(), 'alpha', 'beta'])
self.assertEquals(person.getRegionList(), [person.getRelativeUrl(), 'beta', 'alpha'])
person.setRegion([person.getRelativeUrl(), 'alpha', 'beta'])
self.assertEquals(person.getRegionList(), [person.getRelativeUrl(), 'alpha', 'beta'])
......
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