[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/ZMI - StandardMacros.py:1.1.2.4 ZMIViewService.py:1.1.2.12

Jim Fulton jim@zope.com
Thu, 23 May 2002 14:01:49 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/ZMI
In directory cvs.zope.org:/tmp/cvs-serv26429/lib/python/Zope/App/ZMI

Modified Files:
      Tag: Zope-3x-branch
	StandardMacros.py ZMIViewService.py 
Log Message:
This all started with wanting to be able to use url;view in a ZPT path. :)

That lead me to:

- Massive traversal refactoring.

  Namespace handling is now centralized in Zope.App.Traversing. 

- ZPT refactoring, including some renaming that touches pretty much everything. :)

  - The application specific ZPT support was moved into
    Zope.App.PageTemplate. 

  - To get page template files (for use in views):

    from Zope.App.PageTemplate import ViewPageTemplateFile

  - Fixed up security so that ZPT expressions only have access to 
    safe builtins and so that modules namespace does imports safely.

  - Got ZPTPage working!

- renaming url to absolute_url and got absolute_url to work in paths.

- Cleaned up the (as yet unused) RestrictedInterpreter module in
  Zope.Security. In particular, changed to use a separate
  RestrictedBuiltins module.



=== Zope3/lib/python/Zope/App/ZMI/StandardMacros.py 1.1.2.3 => 1.1.2.4 ===
 """
 
-from Zope.PageTemplate import SimpleViewClass
+from Zope.App.PageTemplate import SimpleViewClass
 
 StandardMacros = SimpleViewClass('www/standard_macros.pt')
 


=== Zope3/lib/python/Zope/App/ZMI/ZMIViewService.py 1.1.2.11 => 1.1.2.12 ===
 from Zope.App.Traversing.ITraverser import ITraverser
 from Zope.Security.SecurityManagement import getSecurityManager
-from Zope.PageTemplate.EngineConfig import getEngine
 from Zope.Proxy.ProxyIntrospection import removeAllProxies
+from Zope.App.PageTemplate.Engine import Engine
+from Zope.Exceptions import Unauthorized
 
 
 class ZMIViewService:
@@ -62,37 +63,31 @@
                 
                 if view_value in res:
                     continue
-                
 
-                ## check filter, short circuit if default
-                if not v.filter_string == 'python: 1':
+                if v.filter is not None:
+                    try:
+                        include = v.filter(Engine.getContext(
+                            context = object,
+                            nothing = None))
+                    except Unauthorized:
+                        include = 0
 
-                    if not v.filter( self._createContext(object)):
+                    if not include:
                         continue
                     
                 res.append( view_value )
                 
         return res
 
-    def _createContext(self, object):
-        '''
-        An expression context provides names for TALES expressions.
-        '''
-
-        data = {
-            'context': object,
-            'view': getWrapperContainer(object),
-            'nothing': None,
-            'user': getSecurityManager().getPrincipal(),
-            }
-        return getEngine().getContext(data)
-
 class ZMIViewDescriptor:
+
     def __init__(self, label, action, filter_string):
         self.label = label
         self.action = action
-        self.filter_string = filter_string
-        self.filter = getEngine().compile(filter_string)
+        if filter_string:
+            self.filter = Engine.compile(filter_string)
+        else:
+            self.filter = None
 
 ZMIViews = ZMIViewService()