From 2eca00a3dbbcdb2bd767840d0cebde5d9e172340 Mon Sep 17 00:00:00 2001 From: Malthe Borch Date: Thu, 4 Dec 2008 21:49:51 +0000 Subject: View component registration is now able to use the 'adaptation annotation' scheme (see zope.component.adaptedBy); the change-log entry has detailed information. --- repoze/bfg/zcml.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'repoze/bfg/zcml.py') diff --git a/repoze/bfg/zcml.py b/repoze/bfg/zcml.py index 960be33bc..aba5847d2 100644 --- a/repoze/bfg/zcml.py +++ b/repoze/bfg/zcml.py @@ -2,10 +2,12 @@ import cPickle import os from os.path import realpath import time +import types from zope.configuration import xmlconfig from zope.component import getSiteManager +from zope.component import adaptedBy import zope.configuration.config from zope.component.interface import provideInterface @@ -36,7 +38,7 @@ def view(_context, for_=None, view=None, name="", - request_type=IRequest, + request_type=None, cacheable=True, ): @@ -50,6 +52,26 @@ def view(_context, args = ('', for_) ) + # views may be either functions or class instances + if isinstance(view, types.FunctionType): + adapted_by = adaptedBy(view) + else: + adapted_by = adaptedBy(type(view)) + + if adapted_by is not None: + try: + if for_ is None: + for_, _ = adapted_by + if request_type is None: + _, request_type = adapted_by + except ValueError: + # the component adaptation annotation does not conform to + # the view specification; we ignore it. + pass + + if request_type is None: + request_type = IRequest + if permission: pfactory = ViewPermissionFactory(permission) _context.action( @@ -150,7 +172,7 @@ def zcml_configure(name, package, load=cPickle.load): return file_configure(name, package) mtime = os.stat(realpath(file)).st_mtime - + if mtime >= ptime: return file_configure(name, package) -- cgit v1.2.3