[Checkins] SVN: Products.CMFDefault/trunk/Products/CMFDefault/browser/search/ Basic search functionality implemented. Batching still needs doing properly.

Charlie Clark charlie at begeistert.org
Sun Oct 10 15:52:31 EDT 2010


Log message for revision 117412:
  Basic search functionality implemented. Batching still needs doing properly.

Changed:
  U   Products.CMFDefault/trunk/Products/CMFDefault/browser/search/interfaces.py
  A   Products.CMFDefault/trunk/Products/CMFDefault/browser/search/results.pt
  U   Products.CMFDefault/trunk/Products/CMFDefault/browser/search/search.pt
  U   Products.CMFDefault/trunk/Products/CMFDefault/browser/search/search.py

-=-
Modified: Products.CMFDefault/trunk/Products/CMFDefault/browser/search/interfaces.py
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/search/interfaces.py	2010-10-10 19:14:42 UTC (rev 117411)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/search/interfaces.py	2010-10-10 19:52:30 UTC (rev 117412)
@@ -27,7 +27,7 @@
 def status_vocab(context):
     """Provides a list of workflow states"""
     catalog = getToolByName(context, 'portal_catalog')
-    values = [((u'--any--'), "None")]
+    values = [(u'--any--', "None")]
     values += [(v, v) for v in catalog.uniqueValuesFor('review_state')]
     return SimpleVocabulary.fromItems(values)
 directlyProvides(status_vocab, IContextSourceBinder)
@@ -35,7 +35,7 @@
 def subject_vocab(context):
     """Provides a list of subject keywords"""
     catalog = getToolByName(context, 'portal_catalog')
-    values = [((u'--any--'), "None")]
+    values = [(u'--any--', "None")]
     values += [(v, v) for v in catalog.uniqueValuesFor('Subject')]
     return SimpleVocabulary.fromItems(values)
 directlyProvides(subject_vocab, IContextSourceBinder)
@@ -76,7 +76,7 @@
     """Provides a list of portal types"""
     ttool = getToolByName(context, 'portal_types')
     types = ttool.listTypeInfo()
-    terms = [SimpleTerm(None, None, '--any--')]
+    terms = [SimpleTerm("None", "None", u'--any--')]
     terms += [SimpleTerm(t.getId(), t.getId(), t.Title()) for t in types]
     return SimpleVocabulary(terms)
 directlyProvides(type_vocab, IContextSourceBinder)
@@ -84,65 +84,78 @@
 
 class ISearchSchema(Interface):
 
-    review_state = Choice(
-                        title=(_(u"Review Status")),
-                        source=status_vocab,
-                        description=(_(
+    review_state = List(
+                        title=_(u"Review Status"),
+                        description=_(
                             u"As a reviewer, you may search for items based on"
                             u" their review state. If you wish to constrain"
                             u" results to items in certain states, select them"
-                            u" from this list.")),
-                        default="None"
+                            u" from this list."),
+                        value_type=Choice(
+                            source=status_vocab
+                            ),
+                        required=False
                         )
 
     search_text = TextLine(
-                        title=(_(u"Full Text")),
-                        description=(_(
-                            u"For a simple text search, enter your search term"
-                            u" here. Multiple words may be found by combining"
-                            u" them with AND and OR. This will find text in"
-                            u" items' contents, title and description.")),
-                        required=False
-                        )
+                    title=_(u"Full Text"),
+                    description=_(
+                        u"For a simple text search, enter your search term"
+                        u" here. Multiple words may be found by combining them"
+                        u" with AND and OR. This will find text in items'"
+                        u" contents, title and description."),
+                    required=False
+                    )
 
-    subject = Choice(
-                title=(_(u"Subject")),
-                description=(_(u"")),
-                source=subject_vocab,
-                default="None"
+    Title = TextLine(
+                title=_(u"Title"),
+                required=False
                 )
 
-    description = TextLine(
-                    title=(_(u"Description")),
-                    description=(_(
+    Subject = List(
+                title=_(u"Subject"),
+                description=_(u""),
+                value_type=Choice(
+                    source=subject_vocab
+                    ),
+                required=False
+                )
+
+    Description = TextLine(
+                    title=_(u"Description"),
+                    description=_(
                         u"You may also search the items' descriptions and"
                         u" titles specifically. Multiple words may be found by"
-                        u" combining them with AND and OR.")),
+                        u" combining them with AND and OR."),
                     required=False
                     )
 
-    when = Choice(
-            title=(_(u"Find new items since...")),
+    created = Choice(
+            title=_(u"Find new items since..."),
             description=(_(
                 u"You may find only recent items by selecting a time-frame."
                         )),
             source=date_vocab,
-            default=date.today())
+            default=date.today()
+            )
 
-    portal_type = Choice(
-                    title=(_(u"Item type")),
-                    description=(_(
+    portal_type = List(
+                    title=_(u"Item type"),
+                    description=_(
                         u"You may limit your results to particular kinds of"
                         u" items by selecting them above. To find all kinds of"
-                        u" items, do not select anything.")),
-                    source=type_vocab,
-                    default="None")
+                        u" items, do not select anything."),
+                    value_type=Choice(
+                        source=type_vocab,
+                        ),
+                    required=False,
+                    )
 
     creator = ASCIILine(
-                title=(_(u"Creator")),
-                description=(_(
+                title=_(u"Creator"),
+                description=_(
                     u"To find items by a particular user only, enter their"
                     u" username above. Note that you must enter their username"
-                    u" exactly.")),
+                    u" exactly."),
                 required=False
                 )

Added: Products.CMFDefault/trunk/Products/CMFDefault/browser/search/results.pt
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/search/results.pt	                        (rev 0)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/search/results.pt	2010-10-10 19:52:30 UTC (rev 117412)
@@ -0,0 +1,51 @@
+<html metal:use-macro="context/@@standard_macros/page">
+
+<body>
+
+<metal:slot metal:fill-slot="body" i18n:domain="cmf_default">
+
+<h1 tal:content="view/label | nothing ">Search Results</h1>
+
+<table class="SearchResults" tal:condition="view/listBatchItems">
+ <thead>
+  <tr>
+   <td width="16">&nbsp;</td>
+   <th i18n:translate="">Title</th>
+   <th i18n:translate="">Type</th>
+   <th i18n:translate="">Date</th>
+  </tr>
+ </thead>
+ <tbody tal:repeat="item_info view/listBatchItems">
+  <tr>
+   <td
+   ><a href="" tal:condition="item_info/icon"
+       tal:attributes="href item_info/url"
+    ><img src="" border="0" alt="" title=""
+        tal:attributes="src item_info/icon;
+                        alt item_info/type;
+                        title item_info/type" /></a></td>
+   <td
+   ><a href="" tal:attributes="href item_info/url"
+   ><tal:case tal:condition="item_info/title"
+       tal:content="item_info/title">Title</tal:case
+   ><tal:case tal:condition="not:item_info/title"
+       i18n:translate="">(No title)</tal:case></a></td>
+   <td tal:content="item_info/type" i18n:translate="">Type</td>
+   <td tal:content="item_info/date">Date</td>
+  </tr>
+  <tr>
+   <td>&nbsp;</td>
+   <td colspan="3"
+   ><em tal:condition="item_info/description"
+       tal:content="item_info/description">Description</em
+   ><em tal:condition="not:item_info/description"
+       i18n:translate="">(No description)</em></td>
+  </tr>
+ </tbody>
+</table>
+<metal:macro metal:use-macro="context/@@batch_widget/navigation" />
+
+</metal:slot>
+
+</body>
+</html>

Modified: Products.CMFDefault/trunk/Products/CMFDefault/browser/search/search.pt
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/search/search.pt	2010-10-10 19:14:42 UTC (rev 117411)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/search/search.pt	2010-10-10 19:52:30 UTC (rev 117412)
@@ -13,14 +13,17 @@
 
 <form action="." method="post" tal:attributes="action request/ACTUAL_URL">
 
-    <fieldset tal:repeat="widget view/widgets">
-      <label tal:attributes="for widget/name" tal:content="widget/label"></label>
-      <tal:block replace="structure widget" />
-      <legend tal:content="widget/hint"></legend>
-      <tal:block condition="widget/error"
-          replace="structure widget/error" />
-    </fieldset>
+  <tal:block repeat="widget view/hidden_widgets"
+             replace="structure widget/hidden" />
 
+  <fieldset tal:repeat="widget view/widgets">
+    <label tal:attributes="for widget/name" tal:content="widget/label"></label>
+    <tal:block replace="structure widget" />
+    <legend tal:content="widget/hint"></legend>
+    <tal:block condition="widget/error"
+        replace="structure widget/error" />
+  </fieldset>
+
   <div class="buttons">
     <tal:loop tal:repeat="action view/actions"
      tal:replace="structure action/render" />

Modified: Products.CMFDefault/trunk/Products/CMFDefault/browser/search/search.py
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/search/search.py	2010-10-10 19:14:42 UTC (rev 117411)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/search/search.py	2010-10-10 19:52:30 UTC (rev 117412)
@@ -23,23 +23,35 @@
 #
 ##############################################################################
 """Search views"""
+import datetime
 
 from zope.formlib import form
 
 from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
 
 from Products.CMFDefault.formlib.form import EditFormBase
+from Products.CMFDefault.formlib.widgets import ChoiceMultiSelectWidget
 from Products.CMFDefault.utils import Message as _
 from Products.CMFDefault.browser.utils import memoize
+from Products.CMFDefault.browser.content.interfaces import IBatchForm
+from Products.CMFDefault.browser.content.folder import BatchViewBase
 
 from interfaces import ISearchSchema
 
+EPOCH = datetime.date(1970, 1, 1)
 
-class Search(EditFormBase):
+
+class Search(BatchViewBase, EditFormBase):
     """Portal Search Form"""
 
     template = ViewPageTemplateFile("search.pt")
+    results = ViewPageTemplateFile("results.pt")
+    hidden_fields = form.FormFields(IBatchForm)
     form_fields = form.FormFields(ISearchSchema)
+    form_fields['review_state'].custom_widget = ChoiceMultiSelectWidget
+    form_fields['Subject'].custom_widget = ChoiceMultiSelectWidget
+    form_fields['portal_type'].custom_widget = ChoiceMultiSelectWidget
+    prefix = 'form'
 
     actions = form.Actions(
         form.Action(
@@ -50,6 +62,10 @@
             ),
         )
 
+    #def __init__(self, *args):
+        #super(Search, self).__init__(*args)
+        #self.hidden_fields += self.form_fields
+
     @property
     def catalog(self):
         return self._getTool('portal_catalog')
@@ -58,5 +74,36 @@
     def types(self):
         return self._getTool('portal_types')
 
+    def setUpWidgets(self, ignore_request=False):
+        """Create widgets for the folder contents."""
+        super(Search, self).setUpWidgets(ignore_request)
+        self.widgets = form.setUpWidgets(
+                self.form_fields, self.prefix, self.context,
+                self.request, ignore_request=ignore_request)
+
     def handle_search(self, action, data):
-        pass
+        for k, v in data.items():
+            if k in ('review_state', 'Title', 'Subject', 'Description',
+                     'portal_type', 'listCreators'):
+                if type(v) == type([]):
+                    v = filter(None, v)
+                if not v:
+                    del data[k]
+            elif k == 'created' and v == EPOCH:
+                del data[k]
+
+        self._items = self.catalog.searchResults(data)
+        self.template = self.results
+
+    def _get_items(self):
+        return getattr(self, '_items', ())
+
+    def listBatchItems(self):
+        return( {'description': item.Description,
+           'icon': item.getIconURL,
+           'title': item.Title,
+           'type': item.Type,
+           'date': item.Date,
+           'url': item.getURL(),
+           'format': None}
+          for item in self._getBatchObj())



More information about the checkins mailing list