src/pyams_pagelet/metaconfigure.py
changeset 12 fc3542685741
parent 0 44692d47182f
equal deleted inserted replaced
11:bd5143e87b1d 12:fc3542685741
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
    10 # FOR A PARTICULAR PURPOSE.
    10 # FOR A PARTICULAR PURPOSE.
    11 #
    11 #
    12 
    12 
       
    13 """PyAMS_pagelet.metaconfigure module
    13 
    14 
    14 # import standard packages
    15 This module provides handlers for ZCML directives.
       
    16 """
    15 
    17 
    16 # import interfaces
    18 from pyramid.exceptions import ConfigurationError
    17 from pyams_pagelet.interfaces import IPagelet
       
    18 from pyramid.interfaces import IRequest
    19 from pyramid.interfaces import IRequest
    19 
       
    20 # import packages
       
    21 from pyams_pagelet.pagelet import Pagelet
       
    22 from pyramid.exceptions import ConfigurationError
       
    23 from pyramid_zcml import with_context
    20 from pyramid_zcml import with_context
    24 from zope.component import zcml
    21 from zope.component import zcml
    25 from zope.component.interface import provideInterface
    22 from zope.component.interface import provideInterface
    26 from zope.interface import Interface, classImplements
    23 from zope.interface import Interface, classImplements
       
    24 
       
    25 from pyams_pagelet.interfaces import IPagelet
       
    26 from pyams_pagelet.pagelet import Pagelet
    27 
    27 
    28 
    28 
    29 def PageletDirective(_context, name, view,
    29 def PageletDirective(_context, name, view,
    30                      context=Interface,
    30                      context=Interface,
    31                      permission=None,
    31                      permission=None,
    32                      layer=IRequest,
    32                      layer=IRequest,
    33                      **kwargs):
    33                      **kwargs):
       
    34     # pylint: disable=invalid-name
       
    35     """Pagelet ZCML directive"""
       
    36 
    34     if not view:
    37     if not view:
    35         raise ConfigurationError("You must specify a view class.")
    38         raise ConfigurationError("You must specify a view class or interface")
    36     cdict = {}
    39     cdict = {
    37     cdict['__name__'] = name
    40         '__name__': name,
    38     cdict['permission'] = permission
    41         'permission': permission
       
    42     }
    39     cdict.update(kwargs)
    43     cdict.update(kwargs)
    40     new_class = type(view.__name__, (view, Pagelet), cdict)
    44     new_class = type(view.__name__, (view, Pagelet), cdict)
    41 
    45 
    42     classImplements(new_class, IPagelet)
    46     classImplements(new_class, IPagelet)
    43 
    47