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
Léo-Paul Géneau
erp5
Commits
201caf82
Commit
201caf82
authored
Feb 29, 2024
by
Kazuhiko Shiozaki
Committed by
Jérome Perrin
Mar 06, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ERP5Type: set Setter guarantees the order with just removing the duplicates.
parent
00311942
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
6 deletions
+25
-6
bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testERP5Type.py
...tTemplateItem/portal_components/test.erp5.testERP5Type.py
+22
-3
product/ERP5Type/Accessor/List.py
product/ERP5Type/Accessor/List.py
+3
-3
No files found.
bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testERP5Type.py
View file @
201caf82
...
...
@@ -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'
,
'alph
a'
])
self
.
assertEqual
(
sorted
(
person
.
getRegionList
()),
[
'alpha'
,
'bet
a'
])
# 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'
,
...
...
product/ERP5Type/Accessor/List.py
View file @
201caf82
...
...
@@ -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
]
...
...
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