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
Alexander Emmerich
erp5
Commits
c4d41710
Commit
c4d41710
authored
Oct 04, 2022
by
Kazuhiko Shiozaki
Committed by
Arnaud Fontaine
Mar 08, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py2/py3: cmp() and sort(cmp=...) do not exist in Python 3.
also str representation of unicode character is different.
parent
c3699871
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
17 deletions
+39
-17
bt5/erp5_base/MixinTemplateItem/portal_components/mixin.erp5.BuilderMixin.py
...TemplateItem/portal_components/mixin.erp5.BuilderMixin.py
+6
-5
product/CMFCategory/Category.py
product/CMFCategory/Category.py
+17
-4
product/CMFCategory/tests/testCMFCategory.py
product/CMFCategory/tests/testCMFCategory.py
+10
-7
product/ERP5Type/Utils.py
product/ERP5Type/Utils.py
+6
-1
No files found.
bt5/erp5_base/MixinTemplateItem/portal_components/mixin.erp5.BuilderMixin.py
View file @
c4d41710
...
@@ -782,15 +782,16 @@ class BuilderMixin(XMLObject, Amount, Predicate):
...
@@ -782,15 +782,16 @@ class BuilderMixin(XMLObject, Amount, Predicate):
for
i
in
self
.
getPortalObject
().
portal_categories
.
collect_order_group
.
contentValues
():
for
i
in
self
.
getPortalObject
().
portal_categories
.
collect_order_group
.
contentValues
():
category_index_dict
[
i
.
getId
()]
=
i
.
getIntIndex
()
category_index_dict
[
i
.
getId
()]
=
i
.
getIntIndex
()
def
sort_movement_group
(
a
,
b
):
def
sort_movement_group_key
(
a
):
return
cmp
(
category_index_dict
.
get
(
a
.
getCollectOrderGroup
()),
return
(
category_index_dict
.
get
(
b
.
getCollectOrderGroup
()))
or
\
category_index_dict
.
get
(
a
.
getCollectOrderGroup
()),
cmp
(
a
.
getIntIndex
(),
b
.
getIntIndex
())
a
.
getIntIndex
(),
)
if
portal_type
is
None
:
if
portal_type
is
None
:
portal_type
=
self
.
getPortalMovementGroupTypeList
()
portal_type
=
self
.
getPortalMovementGroupTypeList
()
movement_group_list
=
[
x
for
x
in
self
.
contentValues
(
filter
=
{
'portal_type'
:
portal_type
})
\
movement_group_list
=
[
x
for
x
in
self
.
contentValues
(
filter
=
{
'portal_type'
:
portal_type
})
\
if
collect_order_group
is
None
or
collect_order_group
==
x
.
getCollectOrderGroup
()]
if
collect_order_group
is
None
or
collect_order_group
==
x
.
getCollectOrderGroup
()]
return
sorted
(
movement_group_list
,
sort_movement_group
)
return
sorted
(
movement_group_list
,
key
=
sort_movement_group_key
)
# XXX category name is hardcoded.
# XXX category name is hardcoded.
def
getDeliveryMovementGroupList
(
self
,
**
kw
):
def
getDeliveryMovementGroupList
(
self
,
**
kw
):
...
...
product/CMFCategory/Category.py
View file @
c4d41710
...
@@ -42,12 +42,20 @@ from Products.ERP5Type.Core.Folder import Folder
...
@@ -42,12 +42,20 @@ from Products.ERP5Type.Core.Folder import Folder
from
Products.CMFCategory.Renderer
import
Renderer
from
Products.CMFCategory.Renderer
import
Renderer
from
Products.ERP5Type.Utils
import
sortValueList
from
Products.ERP5Type.Utils
import
sortValueList
from
Products.ERP5Type.Cache
import
CachingMethod
from
Products.ERP5Type.Cache
import
CachingMethod
import
six
if
six
.
PY3
:
from
functools
import
cmp_to_key
def
cmp
(
a
,
b
):
return
(
a
>
b
)
-
(
a
<
b
)
DEFAULT_CACHE_FACTORY
=
'erp5_ui_long'
DEFAULT_CACHE_FACTORY
=
'erp5_ui_long'
from
zLOG
import
LOG
from
zLOG
import
LOG
NBSP_UTF8
=
u'
\
xA0
'
.
encode
(
'utf-8'
)
if
six
.
PY2
:
NBSP_UTF8
=
u'
\
xA0
'
.
encode
(
'utf-8'
)
else
:
NBSP_UTF8
=
'
\
xA0
'
manage_addCategoryForm
=
DTMLFile
(
'dtml/category_add'
,
globals
())
manage_addCategoryForm
=
DTMLFile
(
'dtml/category_add'
,
globals
())
...
@@ -331,8 +339,10 @@ class Category(Folder):
...
@@ -331,8 +339,10 @@ class Category(Folder):
if
local_sort_method
:
if
local_sort_method
:
# sort objects at the current level
# sort objects at the current level
child_value_list
=
list
(
child_value_list
)
child_value_list
=
list
(
child_value_list
)
if
six
.
PY2
:
child_value_list
.
sort
(
local_sort_method
)
child_value_list
.
sort
(
local_sort_method
)
else
:
child_value_list
.
sort
(
key
=
cmp_to_key
(
local_sort_method
))
if
recursive
:
if
recursive
:
for
c
in
child_value_list
:
for
c
in
child_value_list
:
# Do not pass sort_on / sort_order parameters intentionally, because
# Do not pass sort_on / sort_order parameters intentionally, because
...
@@ -883,7 +893,10 @@ class BaseCategory(Category):
...
@@ -883,7 +893,10 @@ class BaseCategory(Category):
if
local_sort_method
:
if
local_sort_method
:
# sort objects at the current level
# sort objects at the current level
child_value_list
=
list
(
child_value_list
)
child_value_list
=
list
(
child_value_list
)
if
six
.
PY2
:
child_value_list
.
sort
(
local_sort_method
)
child_value_list
.
sort
(
local_sort_method
)
else
:
child_value_list
.
sort
(
key
=
cmp_to_key
(
local_sort_method
))
if
recursive
:
if
recursive
:
for
c
in
child_value_list
:
for
c
in
child_value_list
:
...
...
product/CMFCategory/tests/testCMFCategory.py
View file @
c4d41710
...
@@ -38,6 +38,9 @@ from Testing.ZopeTestCase.PortalTestCase import PortalTestCase
...
@@ -38,6 +38,9 @@ from Testing.ZopeTestCase.PortalTestCase import PortalTestCase
from
AccessControl.SecurityManagement
import
newSecurityManager
from
AccessControl.SecurityManagement
import
newSecurityManager
from
AccessControl.SecurityManagement
import
noSecurityManager
from
AccessControl.SecurityManagement
import
noSecurityManager
import
six
import
six
if
six
.
PY3
:
def
cmp
(
a
,
b
):
return
(
a
>
b
)
-
(
a
<
b
)
class
TestCMFCategory
(
ERP5TypeTestCase
):
class
TestCMFCategory
(
ERP5TypeTestCase
):
...
@@ -785,31 +788,31 @@ class TestCMFCategory(ERP5TypeTestCase):
...
@@ -785,31 +788,31 @@ class TestCMFCategory(ERP5TypeTestCase):
base_cat
.
getCategoryChildIndentedTitleItemList
(),
base_cat
.
getCategoryChildIndentedTitleItemList
(),
[[
''
,
''
],
[[
''
,
''
],
[
'The Title'
,
'the_id'
],
[
'The Title'
,
'the_id'
],
[
'
\
xc2
\
xa0
\
xc2
\
xa0
The Sub Title'
,
'the_id/the_sub_id'
]],
[
NBSP_UTF8
*
2
+
'
The Sub Title'
,
'the_id/the_sub_id'
]],
)
)
self
.
assertEqual
(
self
.
assertEqual
(
base_cat
.
getCategoryChildTranslatedIndentedTitleItemList
(),
base_cat
.
getCategoryChildTranslatedIndentedTitleItemList
(),
[[
''
,
''
],
[[
''
,
''
],
[
'The Title'
,
'the_id'
],
[
'The Title'
,
'the_id'
],
[
'
\
xc2
\
xa0
\
xc2
\
xa0
The S
\
xc3
\
xbc
b T
\
xc3
\
xaf
tle'
,
'the_id/the_sub_id'
]],
[
NBSP_UTF8
*
2
+
'The Süb Tï
tle'
,
'the_id/the_sub_id'
]],
)
)
self
.
assertEqual
(
self
.
assertEqual
(
base_cat
.
getCategoryChildTranslatedCompactTitleItemList
(),
base_cat
.
getCategoryChildTranslatedCompactTitleItemList
(),
[[
''
,
''
],
[[
''
,
''
],
[
'The Title'
,
'the_id'
],
[
'The Title'
,
'the_id'
],
[
'The S
\
xc3
\
xbc
b T
\
xc3
\
xaf
tle'
,
'the_id/the_sub_id'
]],
[
'The S
üb Tï
tle'
,
'the_id/the_sub_id'
]],
)
)
self
.
assertEqual
(
self
.
assertEqual
(
base_cat
.
getCategoryChildTranslatedLogicalPathItemList
(),
base_cat
.
getCategoryChildTranslatedLogicalPathItemList
(),
[[
''
,
''
],
[[
''
,
''
],
[
'The Title'
,
'the_id'
],
[
'The Title'
,
'the_id'
],
[
'The Title/The S
\
xc3
\
xbc
b T
\
xc3
\
xaf
tle'
,
'the_id/the_sub_id'
]],
[
'The Title/The S
üb Tï
tle'
,
'the_id/the_sub_id'
]],
)
)
self
.
assertEqual
(
self
.
assertEqual
(
base_cat
.
getCategoryChildTranslatedCompactLogicalPathItemList
(),
base_cat
.
getCategoryChildTranslatedCompactLogicalPathItemList
(),
[[
''
,
''
],
[[
''
,
''
],
[
'The Title'
,
'the_id'
],
[
'The Title'
,
'the_id'
],
[
'The Title/The S
\
xc3
\
xbc
b T
\
xc3
\
xaf
tle'
,
'the_id/the_sub_id'
]],
[
'The Title/The S
üb Tï
tle'
,
'the_id/the_sub_id'
]],
)
)
def
test_CategoryChildTitleItemListFilterNodeFilterLeave
(
self
):
def
test_CategoryChildTitleItemListFilterNodeFilterLeave
(
self
):
...
@@ -1363,9 +1366,9 @@ class TestCMFCategory(ERP5TypeTestCase):
...
@@ -1363,9 +1366,9 @@ class TestCMFCategory(ERP5TypeTestCase):
self
.
assertEqual
(
get
(
bc
.
id
),
list
(
'aa'
))
self
.
assertEqual
(
get
(
bc
.
id
),
list
(
'aa'
))
_set
(
bc
.
id
,
list
(
'baa'
))
_set
(
bc
.
id
,
list
(
'baa'
))
self
.
assertEqual
(
get
(
bc
.
id
),
list
(
'aba'
))
self
.
assertEqual
(
get
(
bc
.
id
),
list
(
'aba'
))
_set
(
bc
.
id
,
map
(
base
,
'bb'
)
,
1
)
_set
(
bc
.
id
,
[
base
(
e
)
for
e
in
'bb'
]
,
1
)
self
.
assertEqual
(
get
(
bc
.
id
),
list
(
'bb'
))
self
.
assertEqual
(
get
(
bc
.
id
),
list
(
'bb'
))
_set
(
bc
.
id
,
map
(
base
,
'abb'
)
,
1
)
_set
(
bc
.
id
,
[
base
(
e
)
for
e
in
'abb'
]
,
1
)
self
.
assertEqual
(
get
(
bc
.
id
),
list
(
'bab'
))
self
.
assertEqual
(
get
(
bc
.
id
),
list
(
'bab'
))
_set
(
bc
.
id
,
())
_set
(
bc
.
id
,
())
...
...
product/ERP5Type/Utils.py
View file @
c4d41710
...
@@ -34,6 +34,8 @@ from six import int2byte as chr
...
@@ -34,6 +34,8 @@ from six import int2byte as chr
from
six
import
string_types
as
basestring
from
six
import
string_types
as
basestring
from
six.moves
import
xrange
from
six.moves
import
xrange
import
six
import
six
if
six
.
PY3
:
from
functools
import
cmp_to_key
import
os
import
os
import
re
import
re
import
string
import
string
...
@@ -206,7 +208,10 @@ def sortValueList(value_list, sort_on=None, sort_order=None, **kw):
...
@@ -206,7 +208,10 @@ def sortValueList(value_list, sort_on=None, sort_order=None, **kw):
if
result
!=
0
:
if
result
!=
0
:
break
break
return
result
return
result
if
six
.
PY2
:
sort_kw
=
{
'cmp'
:
sortValues
}
sort_kw
=
{
'cmp'
:
sortValues
}
else
:
sort_kw
=
{
'key'
:
cmp_to_key
(
sortValues
)}
sort_kw_cache
[(
sort_on
,
sort_order
)]
=
sort_kw
sort_kw_cache
[(
sort_on
,
sort_order
)]
=
sort_kw
if
isinstance
(
value_list
,
LazyMap
):
if
isinstance
(
value_list
,
LazyMap
):
...
...
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