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
3985f158
Commit
3985f158
authored
Feb 21, 2019
by
Kazuhiko Shiozaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CMFCategory: keep only the first occurrence of each category while preserving order.
parent
c3f1131f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
6 deletions
+15
-6
product/CMFCategory/CategoryTool.py
product/CMFCategory/CategoryTool.py
+3
-2
product/CMFCategory/tests/testCMFCategory.py
product/CMFCategory/tests/testCMFCategory.py
+12
-4
No files found.
product/CMFCategory/CategoryTool.py
View file @
3985f158
...
@@ -30,7 +30,7 @@
...
@@ -30,7 +30,7 @@
"""
\
"""
\
ERP portal_categories tool.
ERP portal_categories tool.
"""
"""
from
collections
import
deque
from
collections
import
deque
,
OrderedDict
import
re
import
re
from
BTrees.OOBTree
import
OOTreeSet
from
BTrees.OOBTree
import
OOTreeSet
from
Products.ERP5Type.Globals
import
InitializeClass
,
DTMLFile
from
Products.ERP5Type.Globals
import
InitializeClass
,
DTMLFile
...
@@ -1189,7 +1189,8 @@ class CategoryTool(BaseTool):
...
@@ -1189,7 +1189,8 @@ class CategoryTool(BaseTool):
# note that we don't want to cast as set at this point to keep ordering (and duplicates).
# note that we don't want to cast as set at this point to keep ordering (and duplicates).
value
=
[
x
for
x
in
tuple
(
value
)
if
x
!=
relative_url
]
value
=
[
x
for
x
in
tuple
(
value
)
if
x
!=
relative_url
]
context
.
categories
=
value
=
tuple
(
value
)
# Keep only the first occurrence of each category while preserving order.
context
.
categories
=
value
=
tuple
(
OrderedDict
.
fromkeys
(
value
))
if
context
.
isTempDocument
():
if
context
.
isTempDocument
():
return
return
...
...
product/CMFCategory/tests/testCMFCategory.py
View file @
3985f158
...
@@ -221,6 +221,14 @@ class TestCMFCategory(ERP5TypeTestCase):
...
@@ -221,6 +221,14 @@ class TestCMFCategory(ERP5TypeTestCase):
p1
.
setRegionList
(
region_list
)
p1
.
setRegionList
(
region_list
)
self
.
assertEqual
(
p1
.
getRegion
(),
None
)
self
.
assertEqual
(
p1
.
getRegion
(),
None
)
region_list
=
[
self
.
region1
,
self
.
region2
,
self
.
region1
]
p1
.
setRegionList
(
region_list
)
self
.
assertEqual
(
p1
.
getRegionList
(),
self
.
region_list
)
p1
.
setRegionValueList
([
region_value_list
[
0
],
region_value_list
[
1
],
region_value_list
[
0
]])
self
.
assertEqual
(
p1
.
getRegionList
(),
self
.
region_list
)
def
test_03_CategoryValue
(
self
):
def
test_03_CategoryValue
(
self
):
# Test if we can get categories values
# Test if we can get categories values
region_value
=
self
.
portal
.
portal_categories
.
resolveCategory
(
'region/%s'
%
self
.
region1
)
region_value
=
self
.
portal
.
portal_categories
.
resolveCategory
(
'region/%s'
%
self
.
region1
)
...
@@ -1251,13 +1259,13 @@ class TestCMFCategory(ERP5TypeTestCase):
...
@@ -1251,13 +1259,13 @@ class TestCMFCategory(ERP5TypeTestCase):
def
_set
(
*
args
,
**
kw
):
def
_set
(
*
args
,
**
kw
):
return
category_tool
.
_setCategoryMembership
(
person
,
*
args
,
**
kw
)
return
category_tool
.
_setCategoryMembership
(
person
,
*
args
,
**
kw
)
_set
(
bc
.
id
,
list
(
'aa'
))
_set
(
bc
.
id
,
list
(
'aa'
))
self
.
assertEqual
(
get
(
bc
.
id
),
list
(
'a
a
'
))
self
.
assertEqual
(
get
(
bc
.
id
),
list
(
'a'
))
_set
(
bc
.
id
,
list
(
'baa'
))
_set
(
bc
.
id
,
list
(
'baa'
))
self
.
assertEqual
(
get
(
bc
.
id
),
list
(
'ab
a
'
))
self
.
assertEqual
(
get
(
bc
.
id
),
list
(
'ab'
))
_set
(
bc
.
id
,
map
(
base
,
'bb'
),
1
)
_set
(
bc
.
id
,
map
(
base
,
'bb'
),
1
)
self
.
assertEqual
(
get
(
bc
.
id
),
list
(
'b
b
'
))
self
.
assertEqual
(
get
(
bc
.
id
),
list
(
'b'
))
_set
(
bc
.
id
,
map
(
base
,
'abb'
),
1
)
_set
(
bc
.
id
,
map
(
base
,
'abb'
),
1
)
self
.
assertEqual
(
get
(
bc
.
id
),
list
(
'ba
b
'
))
self
.
assertEqual
(
get
(
bc
.
id
),
list
(
'ba'
))
_set
(
bc
.
id
,
())
_set
(
bc
.
id
,
())
def
test_relatedIndex
(
self
):
def
test_relatedIndex
(
self
):
...
...
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