Commit 201caf82 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki Committed by Jérome Perrin

ERP5Type: set Setter guarantees the order with just removing the duplicates.

parent 00311942
......@@ -740,7 +740,7 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
# the list.
self.assertEqual(person.getDefaultRegion(), 'beta')
person.setRegionSet(['alpha', 'beta', 'alpha'])
self.assertEqual(person.getRegionList(), ['beta', 'alpha'])
self.assertEqual(sorted(person.getRegionList()), ['alpha', 'beta'])
# calling a set setter did not change the default region
self.assertEqual(person.getDefaultRegion(), 'beta')
......@@ -2185,6 +2185,10 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
checked_permission=checked_permission)
self.assertSameSet([beta_path, gamma_path], foo.getRegionList())
foo.setRegionList([beta_path])
foo.setRegionSet([gamma_path, beta_path])
self.assertEqual(foo.getRegionList(), [beta_path, gamma_path])
foo.setRegionValue(None)
self.assertEqual(None, foo.getRegion())
# Check setCategoryValueSet accessor
......@@ -2199,6 +2203,10 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
checked_permission=checked_permission)
self.assertSameSet([beta_path, gamma_path], foo.getRegionList())
foo.setRegionValueList([beta])
foo.setRegionValueSet([gamma, beta])
self.assertEqual(foo.getRegionValueList(), [beta, gamma])
# check hasCategory accessors
foo.setRegionValue(None)
self.assertEqual(None, foo.getRegion())
......@@ -2406,12 +2414,23 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
person.setDummyList(['a', 'b'])
self.assertEqual(person.getDummy(), 'a')
self.assertEqual(person.getDummyList(), ['a', 'b'])
self.assertEqual(person.getDummySet(), ['a', 'b'])
self.assertEqual(sorted(person.getDummySet()), ['a', 'b'])
person.setDummySet(['b', 'a', 'c'])
self.assertEqual(person.getDummy(), 'a')
self.assertEqual(sorted(person.getDummyList()), ['a', 'b', 'c'])
person.setDummySet(['b', 'c'])
self.assertEqual(sorted(person.getDummyList()), ['b', 'c'])
person.setDummyList(['a', 'b', 'b'])
self.assertEqual(person.getDummy(), 'a')
self.assertEqual(person.getDummyList(), ['a', 'b', 'b'])
self.assertEqual(sorted(person.getDummySet()), ['a', 'b'])
person.setDummy('value')
self.assertEqual(person.getDummy(), 'value')
self.assertEqual(person.getDummyList(), ['value'])
self.assertEqual(person.getDummySet(), ['value'])
self.assertEqual(sorted(person.getDummySet()), ['value'])
def test_translated_accessors(self):
self._addProperty('Person',
......
......@@ -28,6 +28,7 @@ from __future__ import absolute_import
##############################################################################
from collections import OrderedDict
from .Base import func_code, type_definition, list_types,\
ATTRIBUTE_PREFIX, Method, evaluateTales
from .TypeDefinition import asList, identity
......@@ -80,8 +81,7 @@ class DefaultSetter(Base.Setter):
else:
if self._item_cast is not identity:
value = self._item_cast(value)
list_value = set(getattr(instance, self._storage_id, ()))
list_value.discard(value)
list_value = list(OrderedDict.fromkeys(e for e in getattr(instance, self._storage_id, ()) if e != value))
setattr(instance, self._storage_id, (value,) + tuple(list_value))
class ListSetter(DefaultSetter):
......@@ -145,7 +145,7 @@ class SetSetter(Base.Setter):
if self._item_cast is not identity:
value = [self._item_cast(v) for v in value]
if value:
value = set(value)
value = list(OrderedDict.fromkeys(value))
list_value = getattr(instance, self._storage_id, None)
if list_value:
default_value = list_value[0]
......
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