[Checkins] SVN: z3c.contents/trunk/src/z3c/contents/ Make progress, try to make the search part fully additional

Roger Ineichen roger at projekt01.ch
Sat Apr 12 17:35:53 EDT 2008


Log message for revision 85290:
  Make progress, try to make the search part fully additional
  Move search specific implementation to the new IValues adapter.
  
  Work still in progress ...

Changed:
  U   z3c.contents/trunk/src/z3c/contents/browser.py
  U   z3c.contents/trunk/src/z3c/contents/configure.zcml
  U   z3c.contents/trunk/src/z3c/contents/header.py
  U   z3c.contents/trunk/src/z3c/contents/search.py
  U   z3c.contents/trunk/src/z3c/contents/tests.py
  A   z3c.contents/trunk/src/z3c/contents/value.py

-=-
Modified: z3c.contents/trunk/src/z3c/contents/browser.py
===================================================================
--- z3c.contents/trunk/src/z3c/contents/browser.py	2008-04-12 20:18:55 UTC (rev 85289)
+++ z3c.contents/trunk/src/z3c/contents/browser.py	2008-04-12 21:35:52 UTC (rev 85290)
@@ -31,7 +31,6 @@
 from zope.security.interfaces import Unauthorized
 from zope.traversing.interfaces import TraversalError
 from zope.traversing import api
-from zope.app.container.find import SimpleIdFindFilter
 from zope.app.container.interfaces import IContainerNamesContainer
 from zope.app.container.interfaces import DuplicateIDError
 
@@ -41,7 +40,6 @@
 from z3c.template.template import getPageTemplate
 
 from z3c.contents import interfaces
-from z3c.contents.search import SearchableTextFindFilter
 
 _ = zope.i18nmessageid.MessageFactory('z3c')
 
@@ -152,18 +150,13 @@
     renameItemNotFoundMessage = _('Item not found')
 
     def update(self):
-        # first setup and update search form
-        self.searchForm = ContentsSearchForm(self.context, self.request)
-        self.searchForm.table = self
-        self.searchForm.update()
-
-        # second setup columns and process the items as selected if any
+        # first setup columns and process the items as selected if any
         super(ContentsPage, self).update()
-        # third find out if we support paste
+        # second find out if we support paste
         self.clipboard = queryPrincipalClipboard(self.request)
         self.setupCopyPasteMove()
 
-        # fourth setup form part
+        # third setup form part
         self.updateWidgets()
         self.updateActions()
         self.actions.execute()
@@ -193,27 +186,6 @@
         return self.template()
 
     @property
-    def values(self):
-
-        # not searching
-        if not self.searchterm:
-            return self.context.values()
-
-        # no search adapter for the context
-        try:
-            search = interfaces.ISearch(self.context)
-        except TypeError:
-            return self.context.values()
-
-        # perform the search
-        searchterms = self.searchterm.split(' ')
-
-        # 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)])
-
-    @property
     def hasContent(self):
         return bool(self.values)
 

Modified: z3c.contents/trunk/src/z3c/contents/configure.zcml
===================================================================
--- z3c.contents/trunk/src/z3c/contents/configure.zcml	2008-04-12 20:18:55 UTC (rev 85289)
+++ z3c.contents/trunk/src/z3c/contents/configure.zcml	2008-04-12 21:35:52 UTC (rev 85290)
@@ -2,7 +2,12 @@
     xmlns="http://namespaces.zope.org/zope"
     i18n_domain="z3c">
 
+  <!-- IValues-->
   <adapter
+      factory=".value.SearchableValues"
+      />
+
+  <adapter
       name="checkBoxColumn"
       factory="z3c.table.column.CheckBoxColumn"
       for="zope.app.container.interfaces.IContainer

Modified: z3c.contents/trunk/src/z3c/contents/header.py
===================================================================
--- z3c.contents/trunk/src/z3c/contents/header.py	2008-04-12 20:18:55 UTC (rev 85289)
+++ z3c.contents/trunk/src/z3c/contents/header.py	2008-04-12 21:35:52 UTC (rev 85290)
@@ -12,15 +12,14 @@
 #
 ##############################################################################
 """
-$Id:$
+$Id$
 """
 __docformat__ = "reStructuredText"
 
-
 from z3c.table.header import SortingColumnHeader
 
+
 class ContentsColumnHeader(SortingColumnHeader):
     """Sorting column header."""
 
     _request_args = ['search.widgets.searchterm']
-

Modified: z3c.contents/trunk/src/z3c/contents/search.py
===================================================================
--- z3c.contents/trunk/src/z3c/contents/search.py	2008-04-12 20:18:55 UTC (rev 85289)
+++ z3c.contents/trunk/src/z3c/contents/search.py	2008-04-12 21:35:52 UTC (rev 85290)
@@ -95,7 +95,7 @@
     
     def matches(self, object):
         """Check if one of the search terms is found in the searchable text
-        interface
+        interface.
         """
 
         adapter = zope.component.queryAdapter(object, ISearchableText)

Modified: z3c.contents/trunk/src/z3c/contents/tests.py
===================================================================
--- z3c.contents/trunk/src/z3c/contents/tests.py	2008-04-12 20:18:55 UTC (rev 85289)
+++ z3c.contents/trunk/src/z3c/contents/tests.py	2008-04-12 21:35:52 UTC (rev 85290)
@@ -36,6 +36,7 @@
 from z3c.macro import tales
 import z3c.table.testing
 import z3c.contents.search
+import z3c.contents.value
 
 
 class PrincipalAnnotations(dict):
@@ -74,6 +75,9 @@
     # dublin core stub adapter
     zope.component.provideAdapter(z3c.table.testing.DublinCoreAdapterStub)
 
+    # value adapter
+    zope.component.provideAdapter(z3c.contents.value.SearchableValues)
+
     # contents search adapter
     zope.component.provideAdapter(z3c.contents.search.ContentsSearch)
 

Added: z3c.contents/trunk/src/z3c/contents/value.py
===================================================================
--- z3c.contents/trunk/src/z3c/contents/value.py	                        (rev 0)
+++ z3c.contents/trunk/src/z3c/contents/value.py	2008-04-12 21:35:52 UTC (rev 85290)
@@ -0,0 +1,60 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+$Id:$
+"""
+__docformat__ = "reStructuredText"
+
+import zope.component
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.app.container.interfaces import IContainer
+from zope.app.container.find import SimpleIdFindFilter
+
+import z3c.table.value
+from z3c.contents import interfaces
+from z3c.contents import browser
+from z3c.contents.search import SearchableTextFindFilter
+
+
+class SearchableValues(z3c.table.value.ValuesMixin):
+    """Values based on given search."""
+
+    zope.component.adapts(IContainer, IBrowserRequest, interfaces.IContentsPage)
+
+    @property
+    def values(self):
+
+        # first setup and update search form
+        self.table.searchForm = browser.ContentsSearchForm(self.context,
+            self.request)
+        self.table.searchForm.table = self.table
+        self.table.searchForm.update()
+
+        # not searching
+        if not self.table.searchterm:
+            return self.context.values()
+
+        # no search adapter for the context
+        try:
+            search = interfaces.ISearch(self.context)
+        except TypeError:
+            return self.context.values()
+
+        # perform the search
+        searchterms = self.table.searchterm.split(' ')
+
+        # 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)])


Property changes on: z3c.contents/trunk/src/z3c/contents/value.py
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Checkins mailing list