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