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
Laurent S
erp5
Commits
52282904
Commit
52282904
authored
Apr 30, 2018
by
Tomáš Peterka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[erp5_ui] Filter Action prefer own UI version of Action in case of ID duplicates
parent
cd68cb24
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
152 additions
and
5 deletions
+152
-5
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/Base_filterDuplicateActions.py
..._skins/erp5_hal_json_style/Base_filterDuplicateActions.py
+65
-0
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/Base_filterDuplicateActions.xml
...skins/erp5_hal_json_style/Base_filterDuplicateActions.xml
+62
-0
product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/Base_filterDuplicateActions.py
...tal_skins/erp5_xhtml_style/Base_filterDuplicateActions.py
+25
-5
No files found.
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/Base_filterDuplicateActions.py
0 → 100644
View file @
52282904
"""This script filters duplicate actions for a document.
Duplicate actions are actions with the same ID in the same action category or related XHTML category.
In case of duplicate, the JIO version (or the first in the same category) will be kept.
`actions` is the mapping returned by ActionsTool.listFilteredActionsFor
The script must be called on the context of the document.
"""
from
Products.ERP5Type.Cache
import
CachingMethod
def
filterDuplicateActions
(
actions
):
new_actions
=
{}
for
action_category_name
,
action_list
in
actions
.
items
():
# with introduction of the new UI some actions can have JIO only versions
# so we have to consider them as duplicates even though they are in different
# category because those categories are rendered together (e.g object_action and object_jio_action)
is_jio_action_category
=
"_jio_"
in
action_category_name
other_action_id_set
=
set
()
if
is_jio_action_category
:
prefix
,
_
,
suffix
=
action_category_name
.
split
(
"_"
,
2
)
# omit the _jio_
other_action_id_set
.
update
(
action
[
'id'
]
for
action
in
actions
.
get
(
prefix
+
"_"
+
suffix
,
[]))
else
:
if
"_"
in
action_category_name
:
prefix
,
suffix
=
action_category_name
.
split
(
"_"
,
1
)
other_action_id_set
.
update
(
action
[
'id'
]
for
action
in
actions
.
get
(
prefix
+
"_jio_"
+
suffix
,
[]))
existing_actions
=
set
()
new_actions
[
action_category_name
]
=
[]
keep_action
=
new_actions
[
action_category_name
].
append
for
action
in
action_list
:
if
not
is_jio_action_category
:
# prefer JIO version of the same action
if
action
[
'id'
]
in
other_action_id_set
:
continue
if
action
[
'id'
]
not
in
existing_actions
:
existing_actions
.
add
(
action
[
'id'
])
keep_action
(
action
)
return
new_actions
def
hasDuplicateActions
(
portal_type
,
user_name
):
len_actions
=
0
len_filtered_actions
=
0
for
cat
in
actions
.
values
():
len_actions
+=
len
(
cat
)
filtered_actions
=
filterDuplicateActions
(
actions
)
for
cat
in
filtered_actions
.
values
():
len_filtered_actions
+=
len
(
cat
)
return
len_actions
!=
len_filtered_actions
hasDuplicateActions
=
CachingMethod
(
hasDuplicateActions
,
id
=
'Base_filterDuplicateActions.hasDuplicateActions'
,
cache_factory
=
'erp5_ui_long'
)
user_name
=
getattr
(
container
.
REQUEST
,
'AUTHENTICATED_USER'
,
''
)
if
getattr
(
context
,
'getPortalType'
,
None
)
is
not
None
:
if
hasDuplicateActions
(
context
.
getPortalType
(),
user_name
):
return
filterDuplicateActions
(
actions
)
return
actions
bt5/erp5_hal_json_style/SkinTemplateItem/portal_skins/erp5_hal_json_style/Base_filterDuplicateActions.xml
0 → 100644
View file @
52282904
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"PythonScript"
module=
"Products.PythonScripts.PythonScript"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
Script_magic
</string>
</key>
<value>
<int>
3
</int>
</value>
</item>
<item>
<key>
<string>
_bind_names
</string>
</key>
<value>
<object>
<klass>
<global
name=
"NameAssignments"
module=
"Shared.DC.Scripts.Bindings"
/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key>
<string>
_asgns
</string>
</key>
<value>
<dictionary>
<item>
<key>
<string>
name_container
</string>
</key>
<value>
<string>
container
</string>
</value>
</item>
<item>
<key>
<string>
name_context
</string>
</key>
<value>
<string>
context
</string>
</value>
</item>
<item>
<key>
<string>
name_m_self
</string>
</key>
<value>
<string>
script
</string>
</value>
</item>
<item>
<key>
<string>
name_subpath
</string>
</key>
<value>
<string>
traverse_subpath
</string>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key>
<string>
_params
</string>
</key>
<value>
<string>
actions
</string>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
Base_filterDuplicateActions
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/Base_filterDuplicateActions.py
View file @
52282904
"""This script filters duplicate actions for a document.
"""This script filters duplicate actions for a document.
Duplicate actions are actions with the same ID in the same action category.
Duplicate actions are actions with the same ID in the same action category
or related JIO category
.
In case of duplicate,
only the first action
will be kept.
In case of duplicate,
the XHTML version (or the first in the same category)
will be kept.
`actions` is the mapping returned by ActionsTool.listFilteredActionsFor
`actions` is the mapping returned by ActionsTool.listFilteredActionsFor
The script must be called on the context of the document.
The script must be called on the context of the document.
"""
"""
from
Products.ERP5Type.Cache
import
CachingMethod
from
Products.ERP5Type.Cache
import
CachingMethod
def
filterDuplicateActions
(
actions
):
def
filterDuplicateActions
(
actions
):
new_actions
=
{}
new_actions
=
{}
for
action_category
,
action_list
in
actions
.
items
():
for
action_category_name
,
action_list
in
actions
.
items
():
# with introduction of the new UI some actions can have JIO only versions
# so we have to consider them as duplicates even though they are in different
# category because those categories are rendered together (e.g object_action and object_jio_action)
is_jio_action_category
=
"_jio_"
in
action_category_name
other_action_id_set
=
set
()
if
is_jio_action_category
:
prefix
,
_
,
suffix
=
action_category_name
.
split
(
"_"
,
2
)
# omit the _jio_
other_action_id_set
.
update
(
action
[
'id'
]
for
action
in
actions
.
get
(
prefix
+
"_"
+
suffix
,
[]))
else
:
if
"_"
in
action_category_name
:
prefix
,
suffix
=
action_category_name
.
split
(
"_"
,
1
)
other_action_id_set
.
update
(
action
[
'id'
]
for
action
in
actions
.
get
(
prefix
+
"_jio_"
+
suffix
,
[]))
existing_actions
=
set
()
existing_actions
=
set
()
new_actions
[
action_category
]
=
[]
new_actions
[
action_category
_name
]
=
[]
keep_action
=
new_actions
[
action_category
].
append
keep_action
=
new_actions
[
action_category
_name
].
append
for
action
in
action_list
:
for
action
in
action_list
:
if
is_jio_action_category
:
# prefer XHTML version of the same action
if
action
[
'id'
]
in
other_action_id_set
:
continue
if
action
[
'id'
]
not
in
existing_actions
:
if
action
[
'id'
]
not
in
existing_actions
:
existing_actions
.
add
(
action
[
'id'
])
existing_actions
.
add
(
action
[
'id'
])
keep_action
(
action
)
keep_action
(
action
)
return
new_actions
return
new_actions
...
...
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