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
Paul Graydon
erp5
Commits
9b5fbc18
Commit
9b5fbc18
authored
Apr 02, 2019
by
Kazuhiko Shiozaki
Committed by
Kazuhiko Shiozaki
Jan 12, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Predicate: support NULL membership criteria.
parent
a4a3b7bf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
4 deletions
+29
-4
bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testPredicate.py
...TemplateItem/portal_components/test.erp5.testPredicate.py
+22
-0
product/ERP5Catalog/CatalogTool.py
product/ERP5Catalog/CatalogTool.py
+1
-1
product/ERP5Type/Core/Predicate.py
product/ERP5Type/Core/Predicate.py
+6
-3
No files found.
bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testPredicate.py
View file @
9b5fbc18
...
@@ -65,6 +65,12 @@ class TestPredicateMixIn(ERP5TypeTestCase):
...
@@ -65,6 +65,12 @@ class TestPredicateMixIn(ERP5TypeTestCase):
self
.
createCategories
()
self
.
createCategories
()
self
.
login
()
self
.
login
()
def
beforeTearDown
(
self
):
self
.
portal
.
organisation_module
.
manage_delObjects
(
ids
=
list
(
self
.
portal
.
organisation_module
.
objectIds
())
)
self
.
tic
()
def
playSequence
(
self
,
sequence_string
,
quiet
=
QUIET
)
:
def
playSequence
(
self
,
sequence_string
,
quiet
=
QUIET
)
:
# don't commit between steps
# don't commit between steps
sequence
=
Sequence
()
sequence
=
Sequence
()
...
@@ -323,6 +329,22 @@ class TestPredicates(TestPredicateMixIn):
...
@@ -323,6 +329,22 @@ class TestPredicates(TestPredicateMixIn):
[
'region/europe/western_europe/germany'
])
[
'region/europe/western_europe/germany'
])
self
.
assertFalse
(
pred
.
test
(
doc
))
self
.
assertFalse
(
pred
.
test
(
doc
))
def
test_BasicCategoryNullMembership
(
self
):
# if the document is any member of the base category, the predicate returns
# false
doc1
=
self
.
createDocument
()
doc2
=
self
.
createDocument
(
region
=
'europe/western_europe/france'
,)
self
.
tic
()
pred
=
self
.
createPredicate
(
membership_criterion_base_category_list
=
[
'region'
],
membership_criterion_category_list
=
[
'region/NULL'
])
self
.
assertTrue
(
pred
.
test
(
doc1
))
self
.
assertFalse
(
pred
.
test
(
doc2
))
self
.
assertItemsEqual
(
[
doc1
],
[
x
.
getObject
()
for
x
in
pred
.
searchResults
(
portal_type
=
'Organisation'
)]
)
def
test_NonExistantCategoryMembership
(
self
):
def
test_NonExistantCategoryMembership
(
self
):
# the predicate also return false for non existant category and no error is
# the predicate also return false for non existant category and no error is
# raised.
# raised.
...
...
product/ERP5Catalog/CatalogTool.py
View file @
9b5fbc18
...
@@ -1210,7 +1210,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
...
@@ -1210,7 +1210,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
for
base_category_id
,
document_set
in
base_category_dict
.
iteritems
():
for
base_category_id
,
document_set
in
base_category_dict
.
iteritems
():
column
=
prefix
+
base_category_id
+
suffix
column
=
prefix
+
base_category_id
+
suffix
category_query
=
SimpleQuery
(
**
{
category_query
=
SimpleQuery
(
**
{
column
:
{
document
.
getUid
()
for
document
in
document_set
},
column
:
{
None
if
document
is
None
else
document
.
getUid
()
for
document
in
document_set
},
})
})
extra_query
=
onJoin
(
column
)
extra_query
=
onJoin
(
column
)
if
extra_query
is
not
None
:
if
extra_query
is
not
None
:
...
...
product/ERP5Type/Core/Predicate.py
View file @
9b5fbc18
...
@@ -161,14 +161,17 @@ class Predicate(XMLObject):
...
@@ -161,14 +161,17 @@ class Predicate(XMLObject):
isMemberOf
=
context
.
_getCategoryTool
().
isMemberOf
isMemberOf
=
context
.
_getCategoryTool
().
isMemberOf
with
readOnlyTransactionCache
():
with
readOnlyTransactionCache
():
for
c
in
membership_criterion_category_list
:
for
c
in
membership_criterion_category_list
:
bc
=
c
.
split
(
'/'
,
1
)[
0
]
bc
,
c_path
=
c
.
split
(
'/'
,
1
)
is_null
=
c_path
==
'NULL'
if
tested_base_category_list
is
None
or
bc
in
tested_base_category_list
:
if
tested_base_category_list
is
None
or
bc
in
tested_base_category_list
:
if
bc
in
multimembership_criterion_base_category_list
:
if
bc
in
multimembership_criterion_base_category_list
:
if
not
isMemberOf
(
context
,
c
,
strict_membership
=
strict_membership
):
if
(
is_null
and
isMemberOf
(
context
,
bc
,
strict_membership
=
False
))
or
\
not
isMemberOf
(
context
,
c
,
strict_membership
=
strict_membership
):
return
0
return
0
elif
bc
in
membership_criterion_base_category_list
and
\
elif
bc
in
membership_criterion_base_category_list
and
\
not
tested_base_category
.
get
(
bc
):
not
tested_base_category
.
get
(
bc
):
tested_base_category
[
bc
]
=
\
tested_base_category
[
bc
]
=
\
(
is_null
and
not
isMemberOf
(
context
,
bc
,
strict_membership
=
False
))
or
\
isMemberOf
(
context
,
c
,
strict_membership
=
strict_membership
)
isMemberOf
(
context
,
c
,
strict_membership
=
strict_membership
)
if
0
in
tested_base_category
.
itervalues
():
if
0
in
tested_base_category
.
itervalues
():
return
0
return
0
...
@@ -250,7 +253,7 @@ class Predicate(XMLObject):
...
@@ -250,7 +253,7 @@ class Predicate(XMLObject):
getCategoryParameterDict
(
getCategoryParameterDict
(
filterCategoryList
(
getBaseCategorySet
(),
getCategoryList
()),
filterCategoryList
(
getBaseCategorySet
(),
getCategoryList
()),
strict_membership
=
strict_membership
,
strict_membership
=
strict_membership
,
onMissing
=
lambda
category
:
False
,
onMissing
=
lambda
category
:
category
.
split
(
'/'
,
1
)[
1
]
==
'NULL'
,
),
),
)
)
...
...
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