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
Hamza
erp5
Commits
c139fb83
Commit
c139fb83
authored
Apr 02, 2019
by
Kazuhiko Shiozaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Predicate: support NULL membership criteria.
parent
e79e888a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
4 deletions
+28
-4
product/ERP5/tests/testPredicate.py
product/ERP5/tests/testPredicate.py
+21
-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.
product/ERP5/tests/testPredicate.py
View file @
c139fb83
...
...
@@ -65,6 +65,12 @@ class TestPredicateMixIn(ERP5TypeTestCase):
self
.
createCategories
()
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
)
:
# don't commit between steps
sequence
=
Sequence
()
...
...
@@ -323,6 +329,21 @@ class TestPredicates(TestPredicateMixIn):
[
'region/europe/western_europe/germany'
])
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
):
# the predicate also return false for non existant category and no error is
...
...
product/ERP5Catalog/CatalogTool.py
View file @
c139fb83
...
...
@@ -1170,7 +1170,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
for
base_category_id
,
document_set
in
base_category_dict
.
iteritems
():
column
=
prefix
+
base_category_id
+
suffix
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
)
if
extra_query
is
not
None
:
...
...
product/ERP5Type/Core/Predicate.py
View file @
c139fb83
...
...
@@ -159,14 +159,17 @@ class Predicate(XMLObject):
isMemberOf
=
context
.
_getCategoryTool
().
isMemberOf
with
readOnlyTransactionCache
():
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
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
elif
bc
in
membership_criterion_base_category_list
and
\
not
tested_base_category
.
get
(
bc
):
tested_base_category
[
bc
]
=
\
(
is_null
and
not
isMemberOf
(
context
,
bc
,
strict_membership
=
False
))
or
\
isMemberOf
(
context
,
c
,
strict_membership
=
strict_membership
)
if
0
in
tested_base_category
.
itervalues
():
return
0
...
...
@@ -248,7 +251,7 @@ class Predicate(XMLObject):
getCategoryParameterDict
(
filterCategoryList
(
getBaseCategorySet
(),
getCategoryList
()),
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