[Checkins] SVN: z3c.contents/trunk/src/z3c/contents/ review and cleanup,

Roger Ineichen roger at projekt01.ch
Fri Apr 11 17:34:17 EDT 2008


Log message for revision 85260:
  review and cleanup,
  
  I'm not sure right now if the built in search is OK or not right now.
  It looks a little bit complex for the first review. I'll take another 
  closer look later on that topic

Changed:
  U   z3c.contents/trunk/src/z3c/contents/README.txt
  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/contents.pt
  U   z3c.contents/trunk/src/z3c/contents/interfaces.py
  U   z3c.contents/trunk/src/z3c/contents/search.py
  U   z3c.contents/trunk/src/z3c/contents/tests.py

-=-
Modified: z3c.contents/trunk/src/z3c/contents/README.txt
===================================================================
--- z3c.contents/trunk/src/z3c/contents/README.txt	2008-04-11 21:00:34 UTC (rev 85259)
+++ z3c.contents/trunk/src/z3c/contents/README.txt	2008-04-11 21:34:17 UTC (rev 85260)
@@ -44,8 +44,8 @@
   >>> from z3c.form.testing import setupFormDefaults
   >>> setupFormDefaults()
 
-And we need to configure our contents.pt template for the ContentsPage (we
-also configure the template for the search sub form here too)
+And we need to configure our contents.pt template for the ContentsPage. We
+also configure the template for the search sub form here too.
 
   >>> import os
   >>> import sys

Modified: z3c.contents/trunk/src/z3c/contents/browser.py
===================================================================
--- z3c.contents/trunk/src/z3c/contents/browser.py	2008-04-11 21:00:34 UTC (rev 85259)
+++ z3c.contents/trunk/src/z3c/contents/browser.py	2008-04-11 21:34:17 UTC (rev 85260)
@@ -63,25 +63,6 @@
         return default
 
 
-class ContentsSearch(object):
-    """An adapter for container context to satisfy search form requirements
-    
-    """
-
-    zope.interface.implements(interfaces.IContentsSearch)
-    zope.component.adapts(zope.interface.Interface)
-
-    def __init__(self, context):
-        self.context = context
-
-    def get_searchterm(self):
-        return u''
-
-    def set_searchterm(self, value):
-        pass
-
-    searchterm = property(get_searchterm, set_searchterm)
-
 class ContentsSearchForm(form.Form):
 
     template = getPageTemplate()
@@ -127,7 +108,7 @@
     template = getPageTemplate()
 
     # search sub-form
-    search = None
+    searchForm = None
 
     # internal defaults
     selectedItems = []
@@ -171,17 +152,18 @@
     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()
 
-        self.search = ContentsSearchForm(self.context, self.request)
-        self.search.table = self
-        self.search.update()
-
-        # first setup columns and process the items as selected if any
+        # second setup columns and process the items as selected if any
         super(ContentsPage, self).update()
-        # second find out if we support paste
+        # third find out if we support paste
         self.clipboard = queryPrincipalClipboard(self.request)
-
         self.setupCopyPasteMove()
+
+        # fourth setup form part
         self.updateWidgets()
         self.updateActions()
         self.actions.execute()
@@ -229,9 +211,8 @@
         # 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)])
+            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-11 21:00:34 UTC (rev 85259)
+++ z3c.contents/trunk/src/z3c/contents/configure.zcml	2008-04-11 21:34:17 UTC (rev 85260)
@@ -39,15 +39,12 @@
       />
 
   <adapter
-      factory="z3c.contents.browser.ContentsSearch"
+      factory="z3c.contents.search.ContentsSearch"
       />
 
   <adapter
-     provides="z3c.contents.interfaces.ISearch"
-     for="zope.app.container.interfaces.IReadContainer"
-     permission="zope.Public"
-     factory="z3c.contents.search.SearchForContainer"
-     />
+      factory="z3c.contents.search.SearchForContainer"
+      />
 
   <!-- include also sorting column headers for some columns
        leaving out CheckBoxColumn -->

Modified: z3c.contents/trunk/src/z3c/contents/contents.pt
===================================================================
--- z3c.contents/trunk/src/z3c/contents/contents.pt	2008-04-11 21:00:34 UTC (rev 85259)
+++ z3c.contents/trunk/src/z3c/contents/contents.pt	2008-04-11 21:34:17 UTC (rev 85260)
@@ -2,7 +2,7 @@
   <div metal:fill-slot="main">
     <fieldset>
       <legend>Search</legend>
-        <tal:block replace="structure view/search/render">search form</tal:block>
+        <tal:block replace="structure view/searchForm/render">search form</tal:block>
     </fieldset>
     <tal:block replace="structure view/renderTable">table</tal:block>
     <tal:block define="batch view/renderBatch">

Modified: z3c.contents/trunk/src/z3c/contents/interfaces.py
===================================================================
--- z3c.contents/trunk/src/z3c/contents/interfaces.py	2008-04-11 21:00:34 UTC (rev 85259)
+++ z3c.contents/trunk/src/z3c/contents/interfaces.py	2008-04-11 21:34:17 UTC (rev 85260)
@@ -25,9 +25,9 @@
 
 
 class IContentsPage(interfaces.ITable):
-    """Container management page
-    """
+    """Container management page."""
 
+
 class IContentsSearch(zope.interface.Interface):
     """We would like to provide a search field for searching within the
     container.
@@ -36,7 +36,10 @@
     columns.
     """
 
-    searchterm = zope.schema.TextLine(title=_(u'Search'))
+    searchterm = zope.schema.TextLine(
+        title=_(u'Search'),
+        description=_('Search term'),
+        default=u'')
 
 
 class ISearch(zope.interface.Interface):
@@ -54,8 +57,6 @@
         This container itself is not included.
         """
 
+
 class IOrderableColumn(zope.interface.Interface):
-    """
-    A column that may be ordered
-
-    """
+    """A column that may be ordered."""

Modified: z3c.contents/trunk/src/z3c/contents/search.py
===================================================================
--- z3c.contents/trunk/src/z3c/contents/search.py	2008-04-11 21:00:34 UTC (rev 85259)
+++ z3c.contents/trunk/src/z3c/contents/search.py	2008-04-11 21:34:17 UTC (rev 85260)
@@ -18,34 +18,51 @@
 
 import zope.interface
 import zope.component
-from zope.app.container.interfaces import (IObjectFindFilter,
-                                           IReadContainer)
+from zope.app.container.interfaces import IObjectFindFilter
+from zope.app.container.interfaces import IReadContainer
 from zope.security.proxy import removeSecurityProxy
 from zope.index.text.interfaces import ISearchableText
 
-from z3c.contents.interfaces import ISearch
+from z3c.contents import interfaces
 
+
 class SearchForContainer(object):
 
-    zope.interface.implements(ISearch)
+    zope.interface.implements(interfaces.ISearch)
     zope.component.adapts(IReadContainer)
 
     def __init__(self, context):
-        self._context = 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 = []
-        container = self._context
-        for id, object in container.items():
-            _search_helper(id, object, container,
-                         id_filters, object_filters,
-                         result)
+        for id, object in self.context.items():
+            _search_helper(id, object, self.context, id_filters, object_filters,
+                result)
         return result
 
 
+class ContentsSearch(object):
+    """An adapter for container to satisfy search form requirements."""
+
+    zope.interface.implements(interfaces.IContentsSearch)
+    zope.component.adapts(zope.interface.Interface)
+
+    def __init__(self, context):
+        self.context = context
+
+    @apply
+    def searchterm():
+        def get(self):
+            return u''
+        def set(self, value):
+            pass
+        return property(get, set)
+
+
 def _search_helper(id, object, container, id_filters, object_filters, result):
     # check id filters if we get a match then return immediately
     for id_filter in id_filters:
@@ -69,9 +86,7 @@
 
 
 class SearchableTextFindFilter(object):
-    """Filter objects on the ISearchableText adapters to the object
-    
-    """
+    """Filter objects on the ISearchableText adapters to the object."""
 
     zope.interface.implements(IObjectFindFilter)
     
@@ -91,4 +106,3 @@
             if term in searchable:
                 return True
         return False
-

Modified: z3c.contents/trunk/src/z3c/contents/tests.py
===================================================================
--- z3c.contents/trunk/src/z3c/contents/tests.py	2008-04-11 21:00:34 UTC (rev 85259)
+++ z3c.contents/trunk/src/z3c/contents/tests.py	2008-04-11 21:34:17 UTC (rev 85260)
@@ -34,8 +34,8 @@
 from zope.app.testing import setup
 
 from z3c.macro import tales
-import z3c.table.testing 
-from z3c.contents import browser
+import z3c.table.testing
+import z3c.contents.search
 
 
 class PrincipalAnnotations(dict):
@@ -75,7 +75,7 @@
     zope.component.provideAdapter(z3c.table.testing.DublinCoreAdapterStub)
 
     # contents search adapter
-    zope.component.provideAdapter(browser.ContentsSearch)
+    zope.component.provideAdapter(z3c.contents.search.ContentsSearch)
 
 
 def tearDown(test):



More information about the Checkins mailing list