[svn] / z3 / Five / trunk / viewattribute.py Repository:
ViewVC logotype

View of /z3/Five/trunk/viewattribute.py

Parent Directory Parent Directory | Revision Log Revision Log

Revision 46891 - (download) (as text) (annotate)
Wed Jun 16 12:54:00 2004 UTC (9 years, 10 months ago) by faassen
File size: 1715 byte(s)
Initial import of Five. This is a cvs export of cvs.infrae.com/Five.
import Acquisition
from AccessControl import getSecurityManager
from zExceptions import Unauthorized

from zope.component import getView

class FiveViewError(Exception):

class ViewAttribute(Acquisition.Explicit):
    def __init__(self, view_type):
        self._view_type = view_type
    def index_html(self):
        """Default method on view
        # need this info to do security checks, so can't delegate to
        # __getitem__
        obj = self.aq_parent
        view = getView(obj, self._view_type, self.aq_acquire('REQUEST'))
        view = view.__of__(obj)
        method_on_view = getattr(view, 'index_html', None)
        if method_on_view is None:
            raise FiveViewError, "No default view (index_html)"
        security_manager = getSecurityManager()
        if not security_manager.validate(method_on_view, obj, 'index_html',
            raise Unauthorized        
        return method_on_view()
    def __getitem__(self, name):
        """Get correct method on view
        # get the object we are viewing
        obj = self.aq_parent
        # look up the view
        view = getView(obj, self._view_type, self.aq_acquire('REQUEST'))
        # wrap it in the right acquisition context for security
        view = view.__of__(obj)
        # look up method
        method_on_view = getattr(view, name, None)
        if method_on_view is None:
            # we do not accept calling unknown methods
            raise FiveViewError, "Unknown view method: %s" % name 
        # let the ZPublisher do the calling, its security kicks in
        return method_on_view

zope.org Infrastructure
ViewVC Help
Powered by ViewVC 1.0.3