Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alecs_myu
erp5
Commits
74860c01
Commit
74860c01
authored
Apr 29, 2019
by
Kazuhiko Shiozaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Accessor: keep order in Set type category accessor.
Note that Set type setter still keeps the default one if exists.
parent
7cc3d26d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
17 deletions
+23
-17
product/ERP5Type/Accessor/Category.py
product/ERP5Type/Accessor/Category.py
+3
-3
product/ERP5Type/Accessor/Value.py
product/ERP5Type/Accessor/Value.py
+5
-3
product/ERP5Type/tests/testERP5Type.py
product/ERP5Type/tests/testERP5Type.py
+15
-11
No files found.
product/ERP5Type/Accessor/Category.py
View file @
74860c01
...
...
@@ -27,6 +27,7 @@
##############################################################################
from
collections
import
OrderedDict
from
Base
import
func_code
,
type_definition
,
list_types
,
ATTRIBUTE_PREFIX
,
Setter
as
BaseSetter
,
Getter
as
BaseGetter
from
zLOG
import
LOG
from
Products.ERP5Type.PsycoWrapper
import
psyco
...
...
@@ -98,8 +99,7 @@ class SetSetter(ListSetter):
We should take care that the provided argument has no
duplicate values
"""
if
type
(
value
)
not
in
(
set
,
frozenset
):
value
=
frozenset
(
value
)
value
=
tuple
(
OrderedDict
.
fromkeys
(
value
))
instance
.
_setCategoryMembership
(
self
.
_key
,
value
,
spec
=
kw
.
get
(
'spec'
,()),
filter
=
kw
.
get
(
'filter'
,
None
),
...
...
@@ -164,7 +164,7 @@ class SetGetter(ListGetter):
Gets a category value set
"""
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
)))
# ItemList is outdated XXX -> ItemList
...
...
product/ERP5Type/Accessor/Value.py
View file @
74860c01
...
...
@@ -26,6 +26,7 @@
#
##############################################################################
from
collections
import
OrderedDict
from
operator
import
methodcaller
from
Base
import
func_code
,
type_definition
,
list_types
,
ATTRIBUTE_PREFIX
,
Setter
as
BaseSetter
,
Getter
as
BaseGetter
from
zLOG
import
LOG
...
...
@@ -46,10 +47,11 @@ class SetSetter(BaseSetter):
self
.
_key
=
key
self
.
_warning
=
warning
def
__call__
(
self
,
instance
,
*
args
,
**
kw
):
def
__call__
(
self
,
instance
,
value
,
*
args
,
**
kw
):
if
self
.
_warning
:
LOG
(
"ERP5Type Deprecated Setter Id:"
,
0
,
self
.
_id
)
instance
.
_setValue
(
self
.
_key
,
set
(
args
[
0
]),
value
=
tuple
(
OrderedDict
.
fromkeys
(
value
))
instance
.
_setValue
(
self
.
_key
,
value
,
spec
=
kw
.
get
(
'spec'
,()),
filter
=
kw
.
get
(
'filter'
,
None
),
portal_type
=
kw
.
get
(
'portal_type'
,()),
...
...
@@ -164,7 +166,7 @@ class SetGetter(ListGetter):
"""
def
__call__
(
self
,
instance
,
*
args
,
**
kw
):
r
=
ListGetter
.
__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
]
def
defMethodGetter
(
key
,
method
=
None
):
...
...
product/ERP5Type/tests/testERP5Type.py
View file @
74860c01
...
...
@@ -642,23 +642,27 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
person
.
setRegionValueSet
([
alpha
,
alpha
])
self
.
assertEqual
(
person
.
getRegionList
(),
[
'alpha'
])
self
.
assertEqual
(
person
.
getRegionSet
(),
[
'alpha'
])
person
.
setRegionValueList
([
beta
,
alpha
,
beta
])
self
.
assertEqual
(
person
.
getRegionList
(),
[
'beta'
,
'alpha'
,
'beta'
])
self
.
assertEqual
(
person
.
getRegionSet
(),
[
'beta'
,
'alpha'
])
# Order is kept in Set getter.
self
.
assertEqual
(
person
.
getRegionValueSet
(),
[
beta
,
alpha
])
# Order is kept in Set getter.
person
.
setRegionValueList
([
alpha
,
beta
,
alpha
])
self
.
assertEqual
(
person
.
getRegionList
(),
[
'alpha'
,
'beta'
,
'alpha'
])
self
.
assertEqual
(
person
.
getRegionSet
(),
[
'alpha'
,
'beta'
])
self
.
assertEqual
(
person
.
getRegionValueSet
(),
[
alpha
,
beta
])
person
.
setRegionValueSet
([
alpha
,
beta
,
alpha
])
result
=
person
.
getRegionSet
(
)
result
.
sort
(
)
self
.
assertEqual
(
result
,
[
'alpha'
,
'beta'
])
self
.
assertEqual
(
person
.
getRegionList
(),
[
'alpha'
,
'beta'
]
)
person
.
setRegionValueSet
([
beta
,
alpha
,
zeta
,
alpha
]
)
self
.
assertEqual
(
person
.
getRegionList
(),
[
'alpha'
,
'beta'
,
'zeta'
])
# Default is kept, then order is kept in Set setter.
person
.
setDefaultRegionValue
(
beta
)
self
.
assertEqual
(
person
.
getDefaultRegion
(),
'beta'
)
result
=
person
.
getRegionSet
(
)
result
.
sort
(
)
self
.
assertEqual
(
result
,
[
'alpha'
,
'beta'
])
self
.
assertEqual
(
person
.
getRegionList
(),
[
'beta'
,
'alpha'
,
'zeta'
]
)
person
.
setRegion
(
None
)
person
.
setRegionValueSet
([
beta
,
alpha
,
alpha
])
self
.
assertEqual
(
person
.
getRegionList
(),
[
'beta'
,
'alpha'
])
person
.
setDefaultRegionValue
(
alpha
)
self
.
assertEqual
(
person
.
getDefaultRegion
(),
'alpha'
)
result
=
person
.
getRegionSet
()
result
.
sort
()
self
.
assertEqual
(
result
,
[
'alpha'
,
'beta'
])
self
.
assertEqual
(
person
.
getRegionSet
(),
[
'alpha'
,
'beta'
])
self
.
assertEqual
(
person
.
getRegionList
(),
[
'alpha'
,
'beta'
])
# Test accessor on documents rather than on categories
person
.
setDefaultRegionValue
(
person
)
...
...
@@ -678,8 +682,8 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
person
.
setRegionList
([
'alpha'
,
'alpha'
])
self
.
assertEqual
(
person
.
getRegionList
(),
[
'alpha'
,
'alpha'
])
self
.
assertEqual
(
person
.
getRegionSet
(),
[
'alpha'
])
person
.
setRegionSet
([
'beta'
,
'alpha'
,
'alpha'
])
self
.
assertEqual
(
person
.
getRegionList
(),
[
'alpha'
,
'beta'
])
person
.
setRegionSet
([
'beta'
,
'alpha'
,
'
zeta'
,
'
alpha'
])
self
.
assertEqual
(
person
.
getRegionList
(),
[
'alpha'
,
'beta'
,
'zeta'
])
person
.
setRegionList
([
'beta'
,
'alpha'
,
'alpha'
])
self
.
assertEqual
(
person
.
getRegionList
(),
[
'beta'
,
'alpha'
,
'alpha'
])
# at this point the person have a default region set to the first item in
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment