Commit 74571a54 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki Committed by Jérome Perrin

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

parent 201caf82
...@@ -27,6 +27,7 @@ from __future__ import absolute_import ...@@ -27,6 +27,7 @@ from __future__ import absolute_import
# #
############################################################################## ##############################################################################
from collections import OrderedDict
from .Base import func_code, type_definition, list_types, ATTRIBUTE_PREFIX, Getter as BaseGetter from .Base import func_code, type_definition, list_types, ATTRIBUTE_PREFIX, Getter as BaseGetter
from Products.ERP5Type.PsycoWrapper import psyco from Products.ERP5Type.PsycoWrapper import psyco
...@@ -208,4 +209,4 @@ class SetGetter(ListGetter): ...@@ -208,4 +209,4 @@ class SetGetter(ListGetter):
Gets a category value set Gets a category value set
""" """
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
return list(set(ListGetter.__call__(self, instance, *args, **kw))) return list(OrderedDict.fromkeys(ListGetter.__call__(self, instance, *args, **kw)))
...@@ -273,6 +273,6 @@ class SetGetter(ListGetter): ...@@ -273,6 +273,6 @@ class SetGetter(ListGetter):
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
result_list = ListGetter.__call__(self, instance, *args, **kw) result_list = ListGetter.__call__(self, instance, *args, **kw)
if result_list is not None: if result_list is not None:
return list(set(result_list)) return list(OrderedDict.fromkeys(result_list))
Tester = Base.Tester Tester = Base.Tester
...@@ -27,6 +27,7 @@ from __future__ import absolute_import ...@@ -27,6 +27,7 @@ from __future__ import absolute_import
# #
############################################################################## ##############################################################################
from collections import OrderedDict
from .Base import func_code, type_definition, list_types, ATTRIBUTE_PREFIX, Getter as BaseGetter, Setter as BaseSetter from .Base import func_code, type_definition, list_types, ATTRIBUTE_PREFIX, Getter as BaseGetter, Setter as BaseSetter
from Products.ERP5Type.PsycoWrapper import psyco from Products.ERP5Type.PsycoWrapper import psyco
from zLOG import LOG from zLOG import LOG
...@@ -106,4 +107,4 @@ class SetGetter(ListGetter): ...@@ -106,4 +107,4 @@ class SetGetter(ListGetter):
Gets a category value set Gets a category value set
""" """
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
return list(set(ListGetter.__call__(self, instance, *args, **kw))) return list(OrderedDict.fromkeys(ListGetter.__call__(self, instance, *args, **kw)))
...@@ -27,6 +27,7 @@ from __future__ import absolute_import ...@@ -27,6 +27,7 @@ from __future__ import absolute_import
# #
############################################################################## ##############################################################################
from collections import OrderedDict
from .Base import func_code, type_definition, list_types, \ from .Base import func_code, type_definition, list_types, \
ATTRIBUTE_PREFIX, Getter as BaseGetter, Setter as BaseSetter ATTRIBUTE_PREFIX, Getter as BaseGetter, Setter as BaseSetter
from Products.ERP5Type.PsycoWrapper import psyco from Products.ERP5Type.PsycoWrapper import psyco
...@@ -112,7 +113,7 @@ class SetGetter(ListGetter): ...@@ -112,7 +113,7 @@ class SetGetter(ListGetter):
Gets a category value set Gets a category value set
""" """
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
return list(set(ListGetter.__call__(self, instance, *args, **kw))) return list(OrderedDict.fromkeys(ListGetter.__call__(self, instance, *args, **kw)))
class DefaultPropertyGetter(BaseGetter): class DefaultPropertyGetter(BaseGetter):
...@@ -192,7 +193,7 @@ class PropertySetGetter(PropertyListGetter): ...@@ -192,7 +193,7 @@ class PropertySetGetter(PropertyListGetter):
Gets a category value set Gets a category value set
""" """
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
return list(set(PropertyListGetter.__call__(self, instance, *args, **kw))) return list(OrderedDict.fromkeys(PropertyListGetter.__call__(self, instance, *args, **kw)))
class DefaultIdGetter(PropertyGetter): class DefaultIdGetter(PropertyGetter):
......
...@@ -232,7 +232,7 @@ class UidSetSetter(BaseSetter): ...@@ -232,7 +232,7 @@ class UidSetSetter(BaseSetter):
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
if self._warning: if self._warning:
LOG("ERP5Type Deprecated Getter Id:",0, self._id) LOG("ERP5Type Deprecated Getter Id:",0, self._id)
instance._setValueUidList(self._key, set(args[0]), instance._setValueUidList(self._key, list(OrderedDict.fromkeys(args[0])),
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',()),
...@@ -298,4 +298,4 @@ class PropertySetGetter(PropertyListGetter): ...@@ -298,4 +298,4 @@ class PropertySetGetter(PropertyListGetter):
""" """
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
r = PropertyListGetter.__call__(self, instance, **kw) r = PropertyListGetter.__call__(self, instance, **kw)
return list(set(r)) if r or not args else args[0] return list(OrderedDict.fromkeys(r)) if r or not args else args[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