[Zope3-checkins] CVS: Zope3/src/zope/pagetemplate - pagetemplate.py:1.2.8.1

Godefroid Chapelle gotcha@swing.be
Tue, 25 Feb 2003 17:32:19 -0500


Update of /cvs-repository/Zope3/src/zope/pagetemplate
In directory cvs.zope.org:/tmp/cvs-serv18599

Modified Files:
      Tag: template_usage-branch
	pagetemplate.py 
Log Message:
First steps for usage top level variable in TAL namespace

This is meant to maintain a unique template
while allowing to differentiate between ways of using the template.

For example, in action dialogs you need to hide some boxes showed in 
tab views.



=== Zope3/src/zope/pagetemplate/pagetemplate.py 1.2 => 1.2.8.1 ===
--- Zope3/src/zope/pagetemplate/pagetemplate.py:1.2	Wed Dec 25 09:15:13 2002
+++ Zope3/src/zope/pagetemplate/pagetemplate.py	Tue Feb 25 17:32:19 2003
@@ -87,11 +87,12 @@
             text = text.read()
         self.write(text)
 
-    def pt_getContext(self, args=(), options=_default_options, **ignored):
+    def pt_getContext(self, args=(), options=_default_options, template_usage=u'', **ignored):
         rval = {'template': self,
                 'options': options,
                 'args': args,
                 'nothing': None,
+                'usage': TemplateUsage(template_usage),
                 }
         rval.update(self.pt_getEngine().getBaseNames())
         return rval
@@ -199,6 +200,21 @@
             return self.content_type == 'text/html'
         return self.is_html
 
+
+class TemplateUsage:
+    def __init__(self, value):
+        if type(value) <> type(u''):
+            raise TypeError('TemplateUsage should be initialized with a Unicode string : %s' % repr(value))
+        self.stringValue = value
+
+    def __str__(self):
+        return self.stringValue
+
+    def __getitem__(self, key):
+        if key == self.stringValue:
+            return self.stringValue
+        else:
+            return None 
 
 
 class PTRuntimeError(RuntimeError):