Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Kirill Smelkov
Zope
Commits
bda79029
Commit
bda79029
authored
Oct 12, 2012
by
Tom Gross
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed duplicate code in ZopeFind and ZopeFindAndApply
parent
41594f6d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
85 deletions
+51
-85
doc/CHANGES.rst
doc/CHANGES.rst
+2
-0
src/OFS/FindSupport.py
src/OFS/FindSupport.py
+11
-84
src/OFS/tests/testFindSupport.py
src/OFS/tests/testFindSupport.py
+38
-1
No files found.
doc/CHANGES.rst
View file @
bda79029
...
...
@@ -78,6 +78,8 @@ Features Added
Restructuring
+++++++++++++
- OFS: Removed duplicate code in ZopeFind and ZopeFindAndApply
- Five: Removed obsolete metaclass.
- Five: Refactored ``browser:view`` and ``browser:page`` directives.
...
...
src/OFS/FindSupport.py
View file @
bda79029
...
...
@@ -68,88 +68,12 @@ class FindSupport(Base):
search_sub
=
0
,
REQUEST
=
None
,
result
=
None
,
pre
=
''
):
"""Zope Find interface"""
if
result
is
None
:
result
=
[]
if
obj_metatypes
and
'all'
in
obj_metatypes
:
obj_metatypes
=
None
if
obj_mtime
and
type
(
obj_mtime
)
==
type
(
's'
):
obj_mtime
=
DateTime
(
obj_mtime
).
timeTime
()
if
obj_permission
:
obj_permission
=
p_name
(
obj_permission
)
if
obj_roles
and
type
(
obj_roles
)
is
type
(
's'
):
obj_roles
=
[
obj_roles
]
if
obj_expr
:
# Setup expr machinations
md
=
td
()
obj_expr
=
(
Eval
(
obj_expr
),
md
,
md
.
_push
,
md
.
_pop
)
base
=
aq_base
(
obj
)
if
hasattr
(
base
,
'objectItems'
):
try
:
items
=
obj
.
objectItems
()
except
:
return
result
else
:
return
result
try
:
add_result
=
result
.
append
except
:
raise
AttributeError
,
`result`
for
id
,
ob
in
items
:
if
pre
:
p
=
"%s/%s"
%
(
pre
,
id
)
else
:
p
=
id
dflag
=
0
if
hasattr
(
ob
,
'_p_changed'
)
and
(
ob
.
_p_changed
==
None
):
dflag
=
1
bs
=
aq_base
(
ob
)
if
(
(
not
obj_ids
or
absattr
(
bs
.
getId
())
in
obj_ids
)
and
(
not
obj_metatypes
or
(
hasattr
(
bs
,
'meta_type'
)
and
bs
.
meta_type
in
obj_metatypes
))
and
(
not
obj_searchterm
or
(
hasattr
(
ob
,
'PrincipiaSearchSource'
)
and
ob
.
PrincipiaSearchSource
().
find
(
str
(
obj_searchterm
))
>=
0
)
or
(
hasattr
(
ob
,
'SearchableText'
)
and
ob
.
SearchableText
().
find
(
str
(
obj_searchterm
))
>=
0
)
)
and
(
not
obj_expr
or
expr_match
(
ob
,
obj_expr
))
and
(
not
obj_mtime
or
mtime_match
(
ob
,
obj_mtime
,
obj_mspec
))
and
(
(
not
obj_permission
or
not
obj_roles
)
or
\
role_match
(
ob
,
obj_permission
,
obj_roles
)
)
):
add_result
((
p
,
ob
))
dflag
=
0
if
search_sub
and
(
hasattr
(
bs
,
'objectItems'
)):
subob
=
ob
sub_p
=
p
self
.
ZopeFind
(
subob
,
obj_ids
,
obj_metatypes
,
obj_searchterm
,
obj_expr
,
obj_mtime
,
obj_mspec
,
obj_permission
,
obj_roles
,
search_sub
,
REQUEST
,
result
,
sub_p
)
if
dflag
:
ob
.
_p_deactivate
()
return
result
return
self
.
ZopeFindAndApply
(
obj
,
obj_ids
=
obj_ids
,
obj_metatypes
=
obj_metatypes
,
obj_searchterm
=
obj_searchterm
,
obj_expr
=
obj_expr
,
obj_mtime
=
obj_mtime
,
obj_mspec
=
obj_mspec
,
obj_permission
=
obj_permission
,
obj_roles
=
obj_roles
,
search_sub
=
search_sub
,
REQUEST
=
REQUEST
,
result
=
result
,
pre
=
pre
,
apply_func
=
None
,
apply_path
=
''
)
security
.
declareProtected
(
view_management_screens
,
'PrincipiaFind'
)
PrincipiaFind
=
ZopeFind
...
...
@@ -212,8 +136,11 @@ class FindSupport(Base):
and
(
not
obj_searchterm
or
(
hasattr
(
ob
,
'PrincipiaSearchSource'
)
and
ob
.
PrincipiaSearchSource
().
find
(
obj_searchterm
)
>=
0
))
obj_searchterm
in
ob
.
PrincipiaSearchSource
())
or
(
hasattr
(
ob
,
'SearchableText'
)
and
obj_searchterm
in
ob
.
SearchableText
())
)
and
(
not
obj_expr
or
expr_match
(
ob
,
obj_expr
))
and
...
...
src/OFS/tests/testFindSupport.py
View file @
bda79029
import
unittest
from
OFS.FindSupport
import
FindSupport
class
DummyItem
(
FindSupport
):
""" """
def
__init__
(
self
,
id
):
self
.
id
=
id
def
getId
(
self
):
return
self
.
id
class
DummyFolder
(
DummyItem
,
dict
):
def
objectItems
(
self
):
return
self
.
items
()
class
TestFindSupport
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
base
=
DummyFolder
(
'base'
)
self
.
base
[
'1'
]
=
DummyItem
(
'1'
)
self
.
base
[
'2'
]
=
DummyItem
(
'2'
)
self
.
base
[
'3'
]
=
DummyItem
(
'3'
)
def
test_interfaces
(
self
):
from
OFS.interfaces
import
IFindSupport
from
OFS.FindSupport
import
FindSupport
from
zope.interface.verify
import
verifyClass
verifyClass
(
IFindSupport
,
FindSupport
)
def
test_find
(
self
):
self
.
assertEqual
(
self
.
base
.
ZopeFind
(
self
.
base
,
obj_ids
=
[
'1'
])[
0
][
0
],
'1'
)
def
test_find_apply
(
self
):
def
func
(
obj
,
p
):
obj
.
id
=
'foo'
+
obj
.
id
# ZopeFindAndApply does not return anything
# but applies a function to the objects found
self
.
assertFalse
(
self
.
base
.
ZopeFindAndApply
(
self
.
base
,
obj_ids
=
[
'2'
],
apply_func
=
func
))
self
.
assertEqual
(
self
.
base
[
'1'
].
id
,
'1'
)
self
.
assertEqual
(
self
.
base
[
'2'
].
id
,
'foo2'
)
self
.
assertEqual
(
self
.
base
[
'3'
].
id
,
'3'
)
def
test_suite
():
return
unittest
.
TestSuite
((
...
...
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