[Zope3-checkins] SVN: Zope3/trunk/src/zope/ Enable access to session from TALES

Stuart Bishop stuart at stuartbishop.net
Mon Jul 12 13:38:34 EDT 2004


Log message for revision 26430:
Enable access to session from TALES


-=-
Modified: Zope3/trunk/src/zope/app/session/api.txt
===================================================================
--- Zope3/trunk/src/zope/app/session/api.txt	2004-07-12 17:23:57 UTC (rev 26429)
+++ Zope3/trunk/src/zope/app/session/api.txt	2004-07-12 17:38:34 UTC (rev 26430)
@@ -89,23 +89,23 @@
 Page Templates
 --------------
 
-    TODO: Confirm these examples work, preferably by somehow having them
-    unit tested along with the rest of this document
+    Session data may be accessed in page template documents using
+    TALES::
 
-    Session data may be accessed in page template documents using the
-    TALES adaptor syntax::
-
-        <span tal:content="request*Session/products.foo/color | default">
+        <span tal:content="request/session:products.foo/color | default">
             green
         </span>
 
-        <div tal:define="session request*Session/products.foo">
-            <tal:x condition="not:exists:session/count">
-                <tal:x condition="python: session['count'] = 1" />
-            </tal:x>
-            <tal:x condition="exists:session/count">
-                <tal:x condition="python: session['count'] += 1" />
-            </tal:x>
-            <span content="session/count">6</span>
+    or::
+
+        <div tal:define="session request/session:products.foo">
+            <script type="text/server-python">
+                try:
+                    session['count'] += 1
+                except KeyError:
+                    session['count'] = 1
+            </script> 
+
+            <span tal:content="session/count" />
         </div>
 

Modified: Zope3/trunk/src/zope/app/session/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/session/configure.zcml	2004-07-12 17:23:57 UTC (rev 26429)
+++ Zope3/trunk/src/zope/app/session/configure.zcml	2004-07-12 17:38:34 UTC (rev 26430)
@@ -3,21 +3,30 @@
     xmlns:browser="http://namespaces.zope.org/browser">
 
   <adapter
+      for="zope.publisher.interfaces.IRequest"
+      provides=".interfaces.IClientId"
       factory=".session.ClientId"
-      provides=".interfaces.IClientId"
-      for="zope.publisher.interfaces.IRequest"
       permission="zope.Public" 
       />
 
   <adapter
+      for="zope.publisher.interfaces.IRequest"
+      provides=".interfaces.ISession"
       factory=".session.Session"
-      provides=".interfaces.ISession"
+      permission="zope.Public"
+      />
+
+  <adapter
       for="zope.publisher.interfaces.IRequest"
+      provides="zope.app.traversing.interfaces.IPathAdapter"
+      factory=".session.Session"
+      name="session"
       permission="zope.Public"
       />
 
   <content class=".session.Session">
     <allow interface=".interfaces.ISession" />
+    <implements interface="zope.app.traversing.interfaces.IPathAdapter" />
   </content>
 
   <content class=".http.CookieClientIdManager">

Modified: Zope3/trunk/src/zope/app/session/http.py
===================================================================
--- Zope3/trunk/src/zope/app/session/http.py	2004-07-12 17:23:57 UTC (rev 26429)
+++ Zope3/trunk/src/zope/app/session/http.py	2004-07-12 17:38:34 UTC (rev 26430)
@@ -25,6 +25,7 @@
 from zope import schema
 from zope.interface import implements
 from zope.server.http.http_date import build_http_date
+from zope.publisher.interfaces.http import IHTTPApplicationRequest
 import hmac
 import random
 import re
@@ -152,10 +153,10 @@
 
             >>> bim.getRequestId(request) is None
             True
-            >>> id1 = bim.generateUniqueId()
 
         We can set an id:
 
+            >>> id1 = bim.generateUniqueId()
             >>> bim.setRequestId(request, id1)
 
         And get it back:
@@ -178,7 +179,7 @@
             True
 
         """
-
+        request = IHTTPApplicationRequest(request)
         # If there is an id set on the response, use that but don't trust it.
         # We need to check the response in case there has already been a new
         # session created during the course of this request.
@@ -186,7 +187,7 @@
         if response_cookie:
             sid = response_cookie['value']
         else:
-            sid = request.cookies.get(self.namespace)
+            sid = request.getCookies().get(self.namespace, None)
         if sid is None or len(sid) != 54:
             return None
         s, mac = sid[:27], sid[27:]

Modified: Zope3/trunk/src/zope/publisher/http.py
===================================================================
--- Zope3/trunk/src/zope/publisher/http.py	2004-07-12 17:23:57 UTC (rev 26429)
+++ Zope3/trunk/src/zope/publisher/http.py	2004-07-12 17:38:34 UTC (rev 26430)
@@ -420,7 +420,7 @@
     headers = RequestDataProperty(HeaderGetter)
 
     def getCookies(self):
-        'See IHTTPRequest'
+        'See IHTTPApplicationRequest'
         return self._cookies
 
     cookies = RequestDataProperty(CookieMapper)



More information about the Zope3-Checkins mailing list