Source code for grokcore.viewlet.directive
##############################################################################
#
# Copyright (c) 2006-2007 Zope Foundation and Contributors.
# 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.
#
##############################################################################
"""Grok directives.
"""
import martian
from martian.error import GrokError
from martian.util import scan_for_classes
from grokcore.viewlet.interfaces import IViewletManager
[docs]
class viewletmanager(martian.Directive):
scope = martian.CLASS_OR_MODULE
store = martian.ONCE
validate = martian.validateInterfaceOrClass
@classmethod
def get_default(cls, component, module=None, **data):
components = list(scan_for_classes(module, IViewletManager))
if len(components) == 0:
raise GrokError(
"No module-level viewletmanager for %r, please use the "
"'viewletmanager' directive." % (component), component)
elif len(components) == 1:
component = components[0]
else:
raise GrokError(
"Multiple possible viewletmanagers for %r, please use the "
"'viewletmanager' directive."
% (component), component)
return component