[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/index/text - control.pt:1.6 index.py:1.7 interfaces.py:1.5

Guido van Rossum guido@python.org
Fri, 6 Dec 2002 09:49:13 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/index/text
In directory cvs.zope.org:/tmp/cvs-serv14206

Modified Files:
	control.pt index.py interfaces.py 
Log Message:
Do something I really shouldn't: add document links to the query results.
This is done by adding three view helper methods to the IUITextIndex
interface and implementing them, and then using them from the page
template.

Also add reporting of (un)subscribe success to the template.

=== Zope3/lib/python/Zope/App/index/text/control.pt 1.5 => 1.6 ===
--- Zope3/lib/python/Zope/App/index/text/control.pt:1.5	Thu Dec  5 09:57:32 2002
+++ Zope3/lib/python/Zope/App/index/text/control.pt	Fri Dec  6 09:49:11 2002
@@ -21,9 +21,11 @@
 
     <span tal:condition="request/callSubscribe|nothing" tal:omit-tag="">
         <span tal:define="dummy context/subscribe" tal:omit-tag=""/>
+        Successfully subscribed.
     </span>
     <span tal:condition="request/callUnsubscribe|nothing" tal:omit-tag="">
         <span tal:define="dummy context/unsubscribe" tal:omit-tag=""/>
+        Successfully unsubscribed.
     </span>
 
     <div>
@@ -43,6 +45,8 @@
            Subscription state: OFF
            <input type="submit" value="Subscribe" name="callSubscribe" />
        </span>
+       <input type="hidden" name="queryText" value=""
+              tal:attributes="value request/queryText|nothing" />
     </form>
 
     <form method="GET">
@@ -53,13 +57,27 @@
 
     <div tal:condition="request/queryText|nothing" tal:omit-tag="">
         <span tal:define="
-            result_tuple python:context.query(request['queryText']);
+            result_tuple python:context.query(request['queryText'],0,100);
             total python:result_tuple[1];
-            result_list python:result_tuple[0]" tal:omit-tag="">
+            result_list python:result_tuple[0]"
+            tal:omit-tag=""
+            tal:on-error="string:invalid query"
+            >
         Search results: <span tal:replace="total" />
             <div tal:repeat="match_tuple result_list">
-                 Hubid: <span tal:replace="python:match_tuple[0]" />
-                 Score: <span tal:replace="python:match_tuple[1]" />
+              <span tal:define="
+                    hubid    python:match_tuple[0];
+                    score    python:match_tuple[1];
+                    location python:context.hubid2location(hubid);
+                    title    python:context.hubid2title(hubid) or '(no title)';
+                    ">
+                 Location:
+                 <a href="location"
+                    tal:attributes="href location"
+                    tal:content="location">location</a>
+                 Title: <span tal:replace="title" />
+                 Score: <span tal:replace="score" />
+              </span>
             </div>
         </span>
     </div>


=== Zope3/lib/python/Zope/App/index/text/index.py 1.6 => 1.7 ===
--- Zope3/lib/python/Zope/App/index/text/index.py:1.6	Wed Dec  4 16:36:51 2002
+++ Zope3/lib/python/Zope/App/index/text/index.py	Fri Dec  6 09:49:11 2002
@@ -21,23 +21,21 @@
 $Id$
 """
 
+from Zope.ComponentArchitecture import getService, queryAdapter
+from Zope.ContextWrapper import ContextMethod
 from Zope.Event.ISubscriber import ISubscriber
+from Zope.Exceptions import NotFoundError
+from Zope.TextIndex.TextIndexWrapper import TextIndexWrapper
 
-from Zope.ComponentArchitecture import getService
-
+from Zope.App.DublinCore.IZopeDublinCore import IZopeDublinCore
 from Zope.App.OFS.Services.ObjectHub.IHubEvent import \
      IRegistrationHubEvent, \
      IObjectRegisteredHubEvent, \
      IObjectUnregisteredHubEvent, \
      IObjectModifiedHubEvent
-
+from Zope.App.Traversing import locationAsUnicode
 from Zope.App.index.text.interfaces import ISearchableText, IUITextIndex
 
-from Zope.ComponentArchitecture import queryAdapter
-from Zope.ContextWrapper import ContextMethod
-
-from Zope.TextIndex.TextIndexWrapper import TextIndexWrapper
-
 class TextIndex(TextIndexWrapper):
 
     __implements__ = (TextIndexWrapper.__implements__,
@@ -101,3 +99,33 @@
             if texts is not None:
                 wrapped_self.index_doc(hubid, texts)
     _update = ContextMethod(_update)
+
+    # Helpers for the view (XXX should be in a separate view class!)
+
+    def hubid2location(wrapped_self, hubid):
+        channel = getService(wrapped_self, "ObjectHub")
+        try:
+            return locationAsUnicode(channel.getLocation(hubid))
+        except NotFoundError:
+            return ""
+    hubid2location = ContextMethod(hubid2location)
+
+    def hubid2object(wrapped_self, hubid):
+        channel = getService(wrapped_self, "ObjectHub")
+        try:
+            return channel.getObject(hubid)
+        except NotFoundError:
+            return ""
+    hubid2object = ContextMethod(hubid2object)
+
+    def hubid2title(wrapped_self, hubid):
+        channel = getService(wrapped_self, "ObjectHub")
+        try:
+            object = channel.getObject(hubid)
+        except NotFoundError:
+            return ""
+        dc = queryAdapter(object, IZopeDublinCore, context=wrapped_self)
+        if dc is None:
+            return ""
+        return dc.title
+    hubid2title = ContextMethod(hubid2title)


=== Zope3/lib/python/Zope/App/index/text/interfaces.py 1.4 => 1.5 ===
--- Zope3/lib/python/Zope/App/index/text/interfaces.py:1.4	Thu Dec  5 04:52:07 2002
+++ Zope3/lib/python/Zope/App/index/text/interfaces.py	Fri Dec  6 09:49:11 2002
@@ -46,3 +46,18 @@
 
     def isSubscribed():
         """Return whether we are currently subscribed."""
+
+    # XXX The following are blatant view helpers.  Need refactoring.
+
+    def hubid2location(hubid):
+        """Return a location string given a hubid."""
+
+    def hubid2object(hubid):
+        """Return an object given a hubid."""
+
+    def hubid2title(hubid):
+        """Return the Dublin Core title of the object from the hubid.
+
+        Return '' if there is no object or if it isn't adaptable to
+        IZopeDublinCore.
+        """