Ejemplo n.º 1
0
 def __init__(
     self, name, path=None, attribute="render", interface=Interface, permission="view", strict=True, _level=2
 ):
     """ see ``registerTile`` for details on the other parameters.
     """
     self.name = name
     if path and not (":" in path or os.path.isabs(path)):
         path = "%s:%s" % (caller_package(_level).__name__, path)
     self.path = path
     self.attribute = attribute
     self.interface = interface
     self.permission = permission
     self.strict = strict
Ejemplo n.º 2
0
def registerTile(
    name, path=None, attribute="render", interface=Interface, class_=Tile, permission="view", strict=True, _level=2
):
    """registers a tile.
    
    ``name``
        identifier of the tile (for later lookup).
    
    ``path``
        either relative path to the template or absolute path or path prefixed
        by the absolute package name delimeted by ':'. If ``path`` is used
        ``attribute`` is ignored. 
        
    ``attribute``
        attribute on the given _class to be used to render the tile. Defaults to
        ``render``.
        
    ``interface`` 
        Interface or Class of the bfg model the tile is registered for.
        
    ``class_``
        Class to be used to render the tile. usally ``bda.bfg.tile.Tile`` or a
        subclass of. Promises to implement ``bda.bfg.ITile``.
        
    ``permission`` 
        Enables security checking for this tile. Defaults to ``view``. If set to
        ``None`` security checks are disabled.
        
    ``strict``
        Wether to raise ``Forbidden`` or not. Defaults to ``True``. If set to 
        ``False`` the exception is consumed and an empty unicode string is 
        returned.

    ``_level`` 
        is a bit special to make doctests pass the magic path-detection.
        you must never touch it in application code.
    """
    if path and not (":" in path or os.path.isabs(path)):
        path = "%s:%s" % (caller_package(_level).__name__, path)
    tile = class_(path, attribute, name)
    registry = get_current_registry()
    if permission is not None:
        authn_policy = registry.queryUtility(IAuthenticationPolicy)
        authz_policy = registry.queryUtility(IAuthorizationPolicy)
        tile = _secure_tile(tile, permission, authn_policy, authz_policy, strict)
    registry.registerAdapter(tile, [interface, IRequest], ITile, name, event=False)