[Checkins] SVN: z3c.contents/trunk/src/z3c/contents/ Integrate the
ISearch into the IValues adapter.
Roger Ineichen
roger at projekt01.ch
Sat Apr 12 19:14:03 EDT 2008
Log message for revision 85299:
Integrate the ISearch into the IValues adapter.
this allows us to implement different IValues adapter
for different forms for the same context.
Changed:
U z3c.contents/trunk/src/z3c/contents/README.txt
U z3c.contents/trunk/src/z3c/contents/configure.zcml
U z3c.contents/trunk/src/z3c/contents/interfaces.py
U z3c.contents/trunk/src/z3c/contents/value.py
-=-
Modified: z3c.contents/trunk/src/z3c/contents/README.txt
===================================================================
--- z3c.contents/trunk/src/z3c/contents/README.txt 2008-04-12 22:56:51 UTC (rev 85298)
+++ z3c.contents/trunk/src/z3c/contents/README.txt 2008-04-12 23:14:02 UTC (rev 85299)
@@ -839,13 +839,7 @@
Search
------
-Add an IFind adapter for the search:
-
- >>> from z3c.contents.interfaces import ISearch
- >>> from z3c.contents.value import SearchForContainer
- >>> zope.component.provideAdapter(SearchForContainer)
-
-And also register ISearchableText adapter for the contained objects, the default
+Register ISearchableText adapter for the contained objects, the default
filters for searching include searching the keys (content __name__) and using
an ISearchableText adapter for the contained objects.
Modified: z3c.contents/trunk/src/z3c/contents/configure.zcml
===================================================================
--- z3c.contents/trunk/src/z3c/contents/configure.zcml 2008-04-12 22:56:51 UTC (rev 85298)
+++ z3c.contents/trunk/src/z3c/contents/configure.zcml 2008-04-12 23:14:02 UTC (rev 85299)
@@ -43,10 +43,6 @@
provides="z3c.table.interfaces.IColumn"
/>
- <adapter
- factory="z3c.contents.value.SearchForContainer"
- />
-
<!-- include also sorting column headers for some columns
leaving out CheckBoxColumn -->
<adapter
Modified: z3c.contents/trunk/src/z3c/contents/interfaces.py
===================================================================
--- z3c.contents/trunk/src/z3c/contents/interfaces.py 2008-04-12 22:56:51 UTC (rev 85298)
+++ z3c.contents/trunk/src/z3c/contents/interfaces.py 2008-04-12 23:14:02 UTC (rev 85299)
@@ -58,19 +58,3 @@
title=u'Allow search',
description=(u'Allow search.'),
default=True)
-
-
-class ISearch(zope.interface.Interface):
- """
- Search support for containers.
-
- This is different to z.a.c.interfaces.IFind in that the search method
- will match **any** filter whereas the find method of IFind will match
- if **all** filters match.
- """
-
- def search(id_filters=None, object_filters=None):
- """Find object that matches **any** filters in all sub-objects.
-
- This container itself is not included.
- """
Modified: z3c.contents/trunk/src/z3c/contents/value.py
===================================================================
--- z3c.contents/trunk/src/z3c/contents/value.py 2008-04-12 22:56:51 UTC (rev 85298)
+++ z3c.contents/trunk/src/z3c/contents/value.py 2008-04-12 23:14:02 UTC (rev 85299)
@@ -73,26 +73,6 @@
return False
-class SearchForContainer(object):
- """ISearch for IReadContainer."""
-
- zope.interface.implements(interfaces.ISearch)
- zope.component.adapts(IReadContainer)
-
- def __init__(self, context):
- self.context = context
-
- def search(self, id_filters=None, object_filters=None):
- 'See ISearch'
- id_filters = id_filters or []
- object_filters = object_filters or []
- result = []
- for id, object in self.context.items():
- _search_helper(id, object, self.context, id_filters, object_filters,
- result)
- return result
-
-
class SearchableValues(z3c.table.value.ValuesMixin):
"""Values based on given search."""
@@ -118,16 +98,18 @@
if not searchForm.searchterm:
return self.context.values()
- # no search adapter for the context
- try:
- search = interfaces.ISearch(self.context)
- except TypeError:
+ # setup search filters
+ criterias = searchForm.searchterm.strip().split(' ')
+ if not criterias:
+ # only empty strings given
return self.context.values()
- # perform the search
- searchterms = searchForm.searchterm.split(' ')
+ result = []
+ id_filters = [SimpleIdFindFilter(criterias)]
+ object_filters = [SearchableTextFindFilter(criterias)]
- # possible enhancement would be to look up these filters as adapters to
- # the container! Maybe we can use catalogs here?
- return search.search(id_filters=[SimpleIdFindFilter(searchterms)],
- object_filters=[SearchableTextFindFilter(searchterms)])
+ # query items
+ for key, value in self.context.items():
+ _search_helper(key, value, self.context, id_filters, object_filters,
+ result)
+ return result
More information about the Checkins
mailing list