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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xiaowu Zhang
erp5
Commits
cd1859ef
Commit
cd1859ef
authored
Jun 08, 2017
by
Vincent Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CatalogTool: Add getCategoryParameterDict
parent
4bcf5c6a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
0 deletions
+51
-0
product/ERP5Catalog/CatalogTool.py
product/ERP5Catalog/CatalogTool.py
+51
-0
No files found.
product/ERP5Catalog/CatalogTool.py
View file @
cd1859ef
...
@@ -1053,6 +1053,57 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
...
@@ -1053,6 +1053,57 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
)
)
return
related_key_list
return
related_key_list
security
.
declarePublic
(
'getCategoryParameterDict'
)
def
getCategoryParameterDict
(
self
,
category_list
,
strict_membership
=
True
,
forward
=
True
,
onMissing
=
lambda
category
:
True
):
"""
From a list of categories, produce a catalog keyword argument dictionary
testing (strict or not, forward or reverse relation) membership to these
categories.
category_list (list of category relative urls with their base categories)
strict_membership (bool)
Whether intermediate relation members should be excluded (true) or
included (false).
forward (bool)
Whether document being looked up bears the relation (true) or is its
target (false).
onMissing (callable)
Called for each category which does not exist.
Receives faulty relative url as "category" argument.
False return value skips the entry.
True return value causes a None placeholder to be inserted.
Raised exceptions will propagate.
Return a dictionnary whose keys are catalog parameter names and values
are sets of uids.
"""
flag_list
=
[]
if
category_table
!=
'category'
:
raise
ValueError
(
'Unknown category table %r'
%
(
category_table
,
))
if
strict_membership
:
flag_list
.
append
(
'strict'
)
prefix
=
(
'_'
.
join
(
flag_list
)
+
'__'
)
if
flag_list
else
''
suffix
=
(
''
if
forward
else
'__related'
)
+
'__uid'
base_category_dict
=
{}
portal_categories
=
self
.
getPortalObject
().
portal_categories
getBaseCategoryId
=
portal_categories
.
getBaseCategoryId
getCategoryUid
=
portal_categories
.
getCategoryUid
for
relative_url
in
category_list
:
category_uid
=
getCategoryUid
(
relative_url
)
if
category_uid
is
not
None
or
onMissing
(
category
=
relative_url
):
base_category_dict
.
setdefault
(
getBaseCategoryId
(
relative_url
),
set
(),
).
add
(
category_uid
)
parent_uid_set
=
base_category_dict
.
pop
(
'parent'
,
None
)
result
=
{
prefix
+
x
+
suffix
:
y
for
x
,
y
in
base_category_dict
.
iteritems
()
}
if
parent_uid_set
is
not
None
:
result
[
'parent_uid'
]
=
parent_uid_set
return
result
def
_aq_dynamic
(
self
,
name
):
def
_aq_dynamic
(
self
,
name
):
"""
"""
Automatic related key generation.
Automatic related key generation.
...
...
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