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

Guido van Rossum guido@python.org
Wed, 4 Dec 2002 15:00:53 -0500


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

Modified Files:
	control.pt index.py interfaces.py 
Log Message:
Hook the (un)subscribe methods up to the control view.
This required adding a new method (and instance variable) to record and
report the subscription state.

=== Zope3/lib/python/Zope/App/index/text/control.pt 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/App/index/text/control.pt:1.1	Wed Dec  4 14:04:50 2002
+++ Zope3/lib/python/Zope/App/index/text/control.pt	Wed Dec  4 15:00:52 2002
@@ -4,6 +4,13 @@
 
     <h1>TextIndex</h1>
 
+    <span tal:condition="request/callSubscribe|nothing" tal:omit-tag="">
+        <span tal:define="dummy context/subscribe" tal:omit-tag=""/>
+    </span>
+    <span tal:condition="request/callUnsubscribe|nothing" tal:omit-tag="">
+        <span tal:define="dummy context/unsubscribe" tal:omit-tag=""/>
+    </span>
+
     <div>
     	Documents: <span tal:replace="context/documentCount" />
     </div>
@@ -11,6 +18,17 @@
     <div>
     	Words: <span tal:replace="context/wordCount" />
     </div>
+
+    <form method="POST">
+       <span tal:condition="context/isSubscribed" tal:omit-tag="">
+           Subscription state: ON
+           <input type="submit" value="Unsubscribe" name="callUnsubscribe" />
+       </span>
+       <span tal:condition="not:context/isSubscribed" tal:omit-tag="">
+           Subscription state: OFF
+           <input type="submit" value="Subscribe" name="callSubscribe" />
+       </span>
+    </form>
 
   </body>
 


=== Zope3/lib/python/Zope/App/index/text/index.py 1.4 => 1.5 ===
--- Zope3/lib/python/Zope/App/index/text/index.py:1.4	Wed Dec  4 12:11:51 2002
+++ Zope3/lib/python/Zope/App/index/text/index.py	Wed Dec  4 15:00:52 2002
@@ -62,23 +62,34 @@
         return adapted.getSearchableText()
     _getTexts = ContextMethod(_getTexts)
 
+    currentlySubscribed = False # Default subscription state
+
     def subscribe(wrapped_self, channel=None, update=True):
+        if wrapped_self.currentlySubscribed:
+            raise RuntimeError, "already subscribed; please unsubscribe first"
         channel = wrapped_self._getChannel(channel)
         channel.subscribe(wrapped_self, IRegistrationHubEvent)
         channel.subscribe(wrapped_self, IObjectModifiedHubEvent)
         if update:
-            wrapped_self._update(channel.iterObjectRegistrations()) 
+            wrapped_self._update(channel.iterObjectRegistrations())
+        wrapped_self.currentlySubscribed = True
     subscribe = ContextMethod(subscribe)
 
     def unsubscribe(wrapped_self, channel=None):
+        if not wrapped_self.currentlySubscribed:
+            raise RuntimeError, "not subscribed; please subscribe first"
         channel = wrapped_self._getChannel(channel)
         channel.unsubscribe(wrapped_self, IObjectModifiedHubEvent)
         channel.unsubscribe(wrapped_self, IRegistrationHubEvent)
+        wrapped_self.currentlySubscribed = False
     unsubscribe = ContextMethod(unsubscribe)
 
+    def isSubscribed(self):
+        return self.currentlySubscribed
+
     def _getChannel(wrapped_self, channel):
         if channel is None:
-            channel = getService(wrapped_self, "ObjectHubService")
+            channel = getService(wrapped_self, "ObjectHub")
         return channel
     _getChannel = ContextMethod(_getChannel)
 


=== Zope3/lib/python/Zope/App/index/text/interfaces.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/App/index/text/interfaces.py:1.2	Wed Dec  4 12:11:51 2002
+++ Zope3/lib/python/Zope/App/index/text/interfaces.py	Wed Dec  4 15:00:52 2002
@@ -41,3 +41,6 @@
 
     def unsubscribe():
         """Unsubscribe from the object hub service."""
+
+    def isSubscribed():
+        """Return whether we are currently subscribed."""