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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
erp5
Commits
257306cd
Commit
257306cd
authored
Jan 10, 2013
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CategoryTool: clean up getCategoryParentUidList
parent
9eee056a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
64 deletions
+13
-64
product/CMFCategory/CategoryTool.py
product/CMFCategory/CategoryTool.py
+13
-17
product/ERP5/Tool/CategoryTool.py
product/ERP5/Tool/CategoryTool.py
+0
-47
No files found.
product/CMFCategory/CategoryTool.py
View file @
257306cd
...
@@ -308,38 +308,34 @@ class CategoryTool( UniqueObject, Folder, Base ):
...
@@ -308,38 +308,34 @@ class CategoryTool( UniqueObject, Folder, Base ):
such as site/group/a/b/c/b1/c1 where b and b1 are both children
such as site/group/a/b/c/b1/c1 where b and b1 are both children
categories of a.
categories of a.
relative_url -- a single relative url of a list of
relative_url -- a single relative url or a list of relative urls
relative urls
strict -- if set to 1, only return uids of parents, not
strict -- if set to 1, only return uids of parents, not
relative_url
relative_url
"""
"""
uid_
dict
=
{}
uid_
set
=
set
()
if
isinstance
(
relative_url
,
str
):
if
isinstance
(
relative_url
,
str
):
relative_url
=
(
relative_url
,)
relative_url
=
(
relative_url
,)
for
path
in
relative_url
:
for
path
in
relative_url
:
try
:
try
:
o
=
self
.
getCategoryValue
(
path
,
base_category
=
base_category
)
o
=
self
.
getCategoryValue
(
path
,
base_category
=
base_category
)
if
o
is
not
None
:
if
o
is
not
None
:
my_base_category
=
self
.
getBaseCategoryId
(
path
)
if
base_category
is
None
:
bo
=
self
.
get
(
my_base_category
,
None
)
my_base_category
=
self
.
getBaseCategoryId
(
path
)
if
bo
is
not
None
:
else
:
bo_uid
=
int
(
bo
.
getUid
())
my_base_category
=
base_category
uid_dict
[(
int
(
o
.
uid
),
bo_uid
,
1
)]
=
1
# Strict Membership
bo_uid
=
self
[
my_base_category
].
getUid
()
if
o
.
meta_type
==
'CMF Category'
or
o
.
meta_type
==
'CMF Base Category'
:
uid_set
.
add
((
o
.
getUid
(),
bo_uid
,
1
))
# Strict Membership
if
not
strict
:
while
o
.
portal_type
==
'Category'
:
# This goes up in the category tree
# This goes up in the category tree
# XXX we should also go up in some other cases....
# XXX we should also go up in some other cases....
# ie. when some documents act as categories
# ie. when some documents act as categories
if
not
strict
:
o
=
o
.
aq_parent
# We want acquisition here without aq_inner
while
o
.
meta_type
==
'CMF Category'
:
uid_set
.
add
((
o
.
getUid
(),
bo_uid
,
0
))
# Non Strict Membership
o
=
o
.
aq_parent
# We want acquisition here without aq_inner
uid_dict
[(
int
(
o
.
uid
),
bo_uid
,
0
)]
=
1
# Non Strict Membership
except
(
KeyError
,
AttributeError
):
except
(
KeyError
,
AttributeError
):
LOG
(
'WARNING: CategoriesTool'
,
0
,
'Unable to find uid for %s'
%
path
)
LOG
(
'WARNING: CategoriesTool'
,
0
,
'Unable to find uid for %s'
%
path
)
return
uid_dict
.
keys
()
return
list
(
uid_set
)
# cast to list for <dtml-in>
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getUids'
)
getUids
=
getCategoryParentUidList
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getCategoryChildUidList'
)
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getCategoryChildUidList'
)
def
getCategoryChildUidList
(
self
,
relative_url
,
base_category
=
None
,
strict
=
0
):
def
getCategoryChildUidList
(
self
,
relative_url
,
base_category
=
None
,
strict
=
0
):
...
...
product/ERP5/Tool/CategoryTool.py
View file @
257306cd
...
@@ -84,53 +84,6 @@ class CategoryTool(CopyContainer, CMFCategoryTool, BaseTool):
...
@@ -84,53 +84,6 @@ class CategoryTool(CopyContainer, CMFCategoryTool, BaseTool):
def
hasContent
(
self
,
id
):
def
hasContent
(
self
,
id
):
return
id
in
self
.
objectIds
()
return
id
in
self
.
objectIds
()
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getCategoryParentUidList'
)
def
getCategoryParentUidList
(
self
,
relative_url
,
base_category
=
None
,
strict
=
0
):
"""
Returns the uids of all categories provided in categorie. This
method can support relative_url such as site/group/a/b/c which
base category is site yet use categories defined in group.
It is also able to use acquisition to create complex categories
such as site/group/a/b/c/b1/c1 where b and b1 are both children
categories of a.
relative_url -- a single relative url of a list of
relative urls
strict -- if set to 1, only return uids of parents, not
relative_url
"""
uid_dict
=
{}
if
type
(
relative_url
)
is
type
(
'a'
):
relative_url
=
(
relative_url
,)
for
path
in
relative_url
:
try
:
o
=
self
.
getCategoryValue
(
path
,
base_category
=
base_category
)
if
o
is
not
None
:
if
base_category
is
None
:
my_base_category
=
self
.
getBaseCategoryId
(
path
)
else
:
my_base_category
=
base_category
bo
=
getattr
(
self
,
my_base_category
,
None
)
if
bo
is
not
None
:
bo_uid
=
bo
.
getUid
()
uid_dict
[(
o
.
getUid
(),
bo_uid
,
1
)]
=
1
# Strict membership
if
o
.
meta_type
==
'ERP5 Category'
or
o
.
meta_type
==
'ERP5 Base Category'
or
\
o
.
meta_type
==
'CMF Category'
or
o
.
meta_type
==
'CMF Base Category'
:
# This goes up in the category tree
# XXX we should also go up in some other cases....
# ie. when some documents act as categories
if
not
strict
:
while
o
.
meta_type
==
'ERP5 Category'
or
o
.
meta_type
==
'CMF Category'
:
o
=
o
.
aq_parent
# We want acquisition here without aq_inner
uid_dict
[(
o
.
getUid
(),
bo_uid
,
0
)]
=
1
# Non strict
except
(
TypeError
,
KeyError
):
LOG
(
'WARNING: CategoriesTool'
,
0
,
'Unable to find uid for %s'
%
path
)
return
uid_dict
.
keys
()
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getUids'
)
getUids
=
getCategoryParentUidList
@
caching_instance_method
(
id
=
'portal_categories.getBaseCategoryDict'
,
cache_factory
=
'erp5_content_long'
,
cache_id_generator
=
lambda
m
,
*
a
,
**
k
:
m
)
@
caching_instance_method
(
id
=
'portal_categories.getBaseCategoryDict'
,
cache_factory
=
'erp5_content_long'
,
cache_id_generator
=
lambda
m
,
*
a
,
**
k
:
m
)
def
getBaseCategoryDict
(
self
):
def
getBaseCategoryDict
(
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