[Checkins] SVN: z3c.contents/branches/darrylcousins/src/z3c/contents/ Added intial steps to using a sub-form for searching within the container. Needed to add adapter for IContentsSearchForm for the single interface attribute. Just simply corrected tests for now

Darryl Cousins darryl at darrylcousins.net.nz
Fri Mar 14 01:29:11 EDT 2008


Log message for revision 84644:
  Added intial steps to using a sub-form for searching within the container. Needed to add adapter for IContentsSearchForm for the single interface attribute. Just simply corrected tests for now

Changed:
  U   z3c.contents/branches/darrylcousins/src/z3c/contents/BROWSER.txt
  U   z3c.contents/branches/darrylcousins/src/z3c/contents/README.txt
  U   z3c.contents/branches/darrylcousins/src/z3c/contents/browser.py
  U   z3c.contents/branches/darrylcousins/src/z3c/contents/browser.zcml
  U   z3c.contents/branches/darrylcousins/src/z3c/contents/configure.zcml
  U   z3c.contents/branches/darrylcousins/src/z3c/contents/contents.pt
  U   z3c.contents/branches/darrylcousins/src/z3c/contents/interfaces.py
  A   z3c.contents/branches/darrylcousins/src/z3c/contents/search.pt
  U   z3c.contents/branches/darrylcousins/src/z3c/contents/tests.py

-=-
Modified: z3c.contents/branches/darrylcousins/src/z3c/contents/BROWSER.txt
===================================================================
--- z3c.contents/branches/darrylcousins/src/z3c/contents/BROWSER.txt	2008-03-14 03:47:07 UTC (rev 84643)
+++ z3c.contents/branches/darrylcousins/src/z3c/contents/BROWSER.txt	2008-03-14 05:29:10 UTC (rev 84644)
@@ -31,6 +31,8 @@
     href="?contents-sortOn=contents-modifiedColumn-3&contents-sortOrder=ascending"
     title="Sort">Modified</a></th>
 
+  >>> #print browser.contents
+
 Sample data set up
 ==================
 

Modified: z3c.contents/branches/darrylcousins/src/z3c/contents/README.txt
===================================================================
--- z3c.contents/branches/darrylcousins/src/z3c/contents/README.txt	2008-03-14 03:47:07 UTC (rev 84643)
+++ z3c.contents/branches/darrylcousins/src/z3c/contents/README.txt	2008-03-14 05:29:10 UTC (rev 84644)
@@ -44,7 +44,8 @@
   >>> from z3c.form.testing import setupFormDefaults
   >>> setupFormDefaults()
 
-And we need to configure our contents.pt template for the ContentsPage:
+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
@@ -53,6 +54,8 @@
   >>> context = xmlconfig.file('meta.zcml', z3c.template)
   >>> contentsTemplate = os.path.join(os.path.dirname(z3c.contents.__file__),
   ...     'contents.pt')
+  >>> searchTemplate = os.path.join(os.path.dirname(z3c.contents.__file__),
+  ...     'search.pt')
   >>> context = xmlconfig.string("""
   ... <configure
   ...     xmlns:z3c="http://namespaces.zope.org/z3c">
@@ -60,8 +63,12 @@
   ...       for="z3c.contents.browser.ContentsPage"
   ...       template="%s"
   ...       />
+  ...   <z3c:template
+  ...       for="z3c.contents.browser.ContentsSearchForm"
+  ...       template="%s"
+  ...       />
   ... </configure>
-  ... """ % contentsTemplate, context=context)
+  ... """ % (contentsTemplate, searchTemplate), context=context)
 
 
 And load the formui confguration, which will make sure that all macros get 
@@ -110,6 +117,7 @@
            &ndash; required
         </div>
       <div>
+  ...
     </div>
     </div>
     <div>
@@ -174,6 +182,7 @@
            &ndash; required
         </div>
       <div>
+  ...
         <table>
           <thead>
             <tr>
@@ -361,6 +370,7 @@
            &ndash; required
         </div>
       <div>
+  ...
         <table>
           <thead>
             <tr>

Modified: z3c.contents/branches/darrylcousins/src/z3c/contents/browser.py
===================================================================
--- z3c.contents/branches/darrylcousins/src/z3c/contents/browser.py	2008-03-14 03:47:07 UTC (rev 84643)
+++ z3c.contents/branches/darrylcousins/src/z3c/contents/browser.py	2008-03-14 05:29:10 UTC (rev 84644)
@@ -34,7 +34,7 @@
 
 from zope.app.container.interfaces import DuplicateIDError
 
-from z3c.form import button
+from z3c.form import button, field
 from z3c.formui import form
 from z3c.table import table
 from z3c.template.template import getPageTemplate
@@ -61,6 +61,34 @@
         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()
+    fields = field.Fields(interfaces.IContentsSearch)
+    prefix = 'search'
+
+    @button.buttonAndHandler(_('Search'), name='search')
+    def handleSearch(self, action):
+        pass
+
+
 # conditions
 def canCut(form):
     return form.supportsCut
@@ -89,6 +117,9 @@
 
     template = getPageTemplate()
 
+    # search sub-form
+    search = None
+
     # internal defaults
     selectedItems = []
     ignoreContext = False
@@ -131,6 +162,10 @@
         super(ContentsPage, self).update()
         # second find out if we support paste
         self.clipboard = queryPrincipalClipboard(self.request)
+
+        self.search = ContentsSearchForm(self.context, self.request)
+        self.search.update()
+
         self.setupCopyPasteMove()
         self.updateWidgets()
         self.updateActions()
@@ -371,3 +406,4 @@
             renameCol = self.columnByName.get('renameColumn')
             if renameCol:
                 renameCol.errorMessages = errorMessages
+

Modified: z3c.contents/branches/darrylcousins/src/z3c/contents/browser.zcml
===================================================================
--- z3c.contents/branches/darrylcousins/src/z3c/contents/browser.zcml	2008-03-14 03:47:07 UTC (rev 84643)
+++ z3c.contents/branches/darrylcousins/src/z3c/contents/browser.zcml	2008-03-14 05:29:10 UTC (rev 84644)
@@ -10,4 +10,10 @@
       layer="zope.publisher.interfaces.browser.IBrowserRequest"
       />
 
+  <z3c:template
+      template="search.pt"
+      for=".browser.ContentsSearchForm"
+      layer="zope.publisher.interfaces.browser.IBrowserRequest"
+      />
+
 </configure>

Modified: z3c.contents/branches/darrylcousins/src/z3c/contents/configure.zcml
===================================================================
--- z3c.contents/branches/darrylcousins/src/z3c/contents/configure.zcml	2008-03-14 03:47:07 UTC (rev 84643)
+++ z3c.contents/branches/darrylcousins/src/z3c/contents/configure.zcml	2008-03-14 05:29:10 UTC (rev 84644)
@@ -38,6 +38,10 @@
       provides="z3c.table.interfaces.IColumn"
       />
 
+  <adapter
+      factory="z3c.contents.browser.ContentsSearch"
+      />
+
   <!-- include also sorting column headers for some columns
        leaving out CheckBoxColumn -->
   <adapter

Modified: z3c.contents/branches/darrylcousins/src/z3c/contents/contents.pt
===================================================================
--- z3c.contents/branches/darrylcousins/src/z3c/contents/contents.pt	2008-03-14 03:47:07 UTC (rev 84643)
+++ z3c.contents/branches/darrylcousins/src/z3c/contents/contents.pt	2008-03-14 05:29:10 UTC (rev 84644)
@@ -1,5 +1,9 @@
 <div metal:use-macro="macro:form">
   <div metal:fill-slot="main">
+    <fieldset>
+      <legend>Search</legend>
+        <tal:block replace="structure view/search/render">search form</tal:block>
+    </fieldset>
     <tal:block replace="structure view/renderTable">table</tal:block>
     <tal:block define="batch view/renderBatch">
     <div class="batch" tal:condition="batch">

Modified: z3c.contents/branches/darrylcousins/src/z3c/contents/interfaces.py
===================================================================
--- z3c.contents/branches/darrylcousins/src/z3c/contents/interfaces.py	2008-03-14 03:47:07 UTC (rev 84643)
+++ z3c.contents/branches/darrylcousins/src/z3c/contents/interfaces.py	2008-03-14 05:29:10 UTC (rev 84644)
@@ -16,7 +16,9 @@
 """
 __docformat__ = "reStructuredText"
 
+import zope.schema
 import zope.i18nmessageid
+
 from z3c.table import interfaces
 
 _ = zope.i18nmessageid.MessageFactory('z3c')
@@ -24,3 +26,13 @@
 
 class IContentsPage(interfaces.ITable):
     """Container management page"""
+
+class IContentsSearch(zope.interface.Interface):
+    """We would like to provide a search field for searching within the
+    container.
+    
+    Possible addition here could be a choice field to search within specific
+    columns.
+    """
+
+    searchterm = zope.schema.TextLine(title=_(u'Search'))

Added: z3c.contents/branches/darrylcousins/src/z3c/contents/search.pt
===================================================================
--- z3c.contents/branches/darrylcousins/src/z3c/contents/search.pt	                        (rev 0)
+++ z3c.contents/branches/darrylcousins/src/z3c/contents/search.pt	2008-03-14 05:29:10 UTC (rev 84644)
@@ -0,0 +1,15 @@
+<table>
+<tr>
+<td class="row" tal:repeat="widget view/widgets/values">
+  <b tal:condition="widget/error"
+     tal:content="structure widget/error/render"
+  /><label for=""
+         tal:attributes="for widget/id"
+         tal:content="widget/label" />
+  <input type="text" tal:replace="structure widget/render"
+/></td>
+<td class="action" tal:repeat="action view/actions/values">
+  <input type="submit" tal:replace="structure action/render"
+/></td>
+</tr>
+</table>

Modified: z3c.contents/branches/darrylcousins/src/z3c/contents/tests.py
===================================================================
--- z3c.contents/branches/darrylcousins/src/z3c/contents/tests.py	2008-03-14 03:47:07 UTC (rev 84643)
+++ z3c.contents/branches/darrylcousins/src/z3c/contents/tests.py	2008-03-14 05:29:10 UTC (rev 84644)
@@ -35,6 +35,7 @@
 
 from z3c.macro import tales
 import z3c.table.testing 
+from z3c.contents import browser
 
 
 class PrincipalAnnotations(dict):
@@ -73,7 +74,10 @@
     # dublin core stub adapter
     zope.component.provideAdapter(z3c.table.testing.DublinCoreAdapterStub)
 
+    # contents search adapter
+    zope.component.provideAdapter(browser.ContentsSearch)
 
+
 def tearDown(test):
     setup.placefulTearDown()
 



More information about the Checkins mailing list