Added 'data' namespace to access request data
authorThierry Florac <tflorac@ulthar.net>
Sat, 28 Aug 2010 02:40:42 +0200
changeset 58 a2b74dda721b
parent 57 74d4ccdc6dbe
child 59 d81fcb734e6c
Added 'data' namespace to access request data
ztfy/utils/tal/configure.zcml
ztfy/utils/tal/interfaces.py
ztfy/utils/tal/request.py
--- a/ztfy/utils/tal/configure.zcml	Tue Jul 27 22:34:47 2010 +0200
+++ b/ztfy/utils/tal/configure.zcml	Sat Aug 28 02:40:42 2010 +0200
@@ -20,4 +20,10 @@
 		provides="zope.traversing.interfaces.IPathAdapter"
 		for="*" />
 
+	<adapter
+		name="data"
+		factory=".request.RequestDataTalesAdapter"
+		provides="zope.traversing.interfaces.IPathAdapter"
+		for="zope.publisher.interfaces.browser.IBrowserRequest" />
+
 </configure>
\ No newline at end of file
--- a/ztfy/utils/tal/interfaces.py	Tue Jul 27 22:34:47 2010 +0200
+++ b/ztfy/utils/tal/interfaces.py	Sat Aug 28 02:40:42 2010 +0200
@@ -64,3 +64,10 @@
 
     def rest():
         """Convert adapted reStructuredText to HTML"""
+
+
+class IRequestDataTalesAPI(Interface):
+    """Request 'data' TALES namespace interface"""
+
+    def __getattr__(attr):
+        """Get request data for given attribute"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy/utils/tal/request.py	Sat Aug 28 02:40:42 2010 +0200
@@ -0,0 +1,44 @@
+### -*- coding: utf-8 -*- ####################################################
+##############################################################################
+#
+# Copyright (c) 2008-2010 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+__docformat__ = "restructuredtext"
+
+# import standard packages
+
+# import Zope3 interfaces
+from zope.tales.interfaces import ITALESFunctionNamespace
+
+# import local interfaces
+from interfaces import IRequestDataTalesAPI
+
+# import Zope3 packages
+from zope.interface import implements
+
+# import local packages
+from ztfy.utils.request import getData
+
+
+class RequestDataTalesAdapter(object):
+
+    implements(IRequestDataTalesAPI, ITALESFunctionNamespace)
+
+    def __init__(self, context):
+        self.context = context
+
+    def setEngine(self, engine):
+        self.request = engine.vars['request']
+
+    def __getattr__(self, attr):
+        return getData(attr, self.context)