예제 #1
0
def viewlet(
    _context, name, permission,
    for_=Interface, layer=interfaces.IFlourishLayer, view=IBrowserView,
    manager=None,
    class_=Viewlet, template=None,
    update='update', render='render',
    allowed_interface=(), allowed_attributes=(),
    **kwargs):

    if not interfaces.IViewlet.implementedBy(class_):
        class_ = type(class_.__name__, (class_, Viewlet), {})
    allowed_interface = (tuple(allowed_interface) +
                         (interfaces.IViewlet, ))

    if (render == 'render' and
        class_.render == Viewlet.render):
        if template:
            render = 'template'
        else:
            raise ConfigurationError("When template and render not specified, "
                                     "class must implement 'render' method")

    class_ = subclass_content(
        class_, name,
        {'update': update, 'render': render},
        update_specs({'template': template}, view), kwargs)

    handle_interfaces(_context, (for_, view))
    handle_interfaces(_context, allowed_interface)

    handle_security(class_, permission,
                    allowed_interface, allowed_attributes)

    _context.action(
        discriminator=('schooltool.skin.flourish.viewlet',
                       for_, layer, view, manager, name),
        callable=zope.component.zcml.handler,
        args=('registerAdapter',
              class_,
              (for_, layer, view, manager),
              interfaces.IViewlet,
              name,
              _context.info),)
예제 #2
0
파일: zcml.py 프로젝트: l1ph0x/schooltool-2
def viewlet(_context,
            name,
            permission,
            for_=Interface,
            layer=interfaces.IFlourishLayer,
            view=IBrowserView,
            manager=None,
            class_=Viewlet,
            template=None,
            update='update',
            render='render',
            allowed_interface=(),
            allowed_attributes=(),
            **kwargs):

    if not interfaces.IViewlet.implementedBy(class_):
        class_ = type(class_.__name__, (class_, Viewlet), {})
    allowed_interface = (tuple(allowed_interface) + (interfaces.IViewlet, ))

    if (render == 'render' and class_.render == Viewlet.render):
        if template:
            render = 'template'
        else:
            raise ConfigurationError("When template and render not specified, "
                                     "class must implement 'render' method")

    class_ = subclass_content(class_, name, {
        'update': update,
        'render': render
    }, update_specs({'template': template}, view), kwargs)

    handle_interfaces(_context, (for_, view))
    handle_interfaces(_context, allowed_interface)

    handle_security(class_, permission, allowed_interface, allowed_attributes)

    _context.action(
        discriminator=('schooltool.skin.flourish.viewlet', for_, layer, view,
                       manager, name),
        callable=zope.component.zcml.handler,
        args=('registerAdapter', class_, (for_, layer, view, manager),
              interfaces.IViewlet, name, _context.info),
    )
예제 #3
0
def page(_context, name, permission,
         for_=Interface, layer=interfaces.IFlourishLayer,
         title=None, subtitle=None,
         template=None, page_template=None, content_template=None,
         class_=Page,
         update='update', render='render',
         allowed_interface=(), allowed_attributes=(),
         **kwargs
         ):

    forward_methods = {
        'update': update,
        'render': render,
        }

    # BBB: add index to ease porting from old style views
    if (IBrowserView.implementedBy(class_) and
        getattr(class_, 'index', None) is None):
        forward_methods['index'] = render

    if not interfaces.IPage.implementedBy(class_):
        class_ = type(class_.__name__, (class_, Page), {})

    allowed_interface = (tuple(allowed_interface) +
                         (interfaces.IPage, ))

    class_dict = dict(kwargs)
    class_dict['__name__'] = name

    if title is not None:
        class_dict['title'] = title
    if subtitle is not None:
        class_dict['subtitle'] = subtitle

    # XXX: raise ConfigurationError if class_ is Page and
    #      no templates specified

    templates = template_specs({
        'template': template,
        'page_template': page_template,
        'content_template': content_template,
        }, content_type='html')

    class_ = subclass_content(
        class_, name,
        forward_methods,
        templates,
        class_dict,
        )

    handle_interfaces(_context, (for_,))
    handle_interfaces(_context, allowed_interface)

    handle_security(class_, permission,
                    allowed_interface, allowed_attributes)

    _context.action(
        discriminator=('view', for_, name, IBrowserRequest, layer),
        callable=zope.component.zcml.handler,
        args=('registerAdapter',
              class_, (for_, layer), Interface, name, _context.info),
        )
예제 #4
0
파일: zcml.py 프로젝트: l1ph0x/schooltool-2
def page(_context,
         name,
         permission,
         for_=Interface,
         layer=interfaces.IFlourishLayer,
         title=None,
         subtitle=None,
         template=None,
         page_template=None,
         content_template=None,
         class_=Page,
         update='update',
         render='render',
         allowed_interface=(),
         allowed_attributes=(),
         **kwargs):

    forward_methods = {
        'update': update,
        'render': render,
    }

    # BBB: add index to ease porting from old style views
    if (IBrowserView.implementedBy(class_)
            and getattr(class_, 'index', None) is None):
        forward_methods['index'] = render

    if not interfaces.IPage.implementedBy(class_):
        class_ = type(class_.__name__, (class_, Page), {})

    allowed_interface = (tuple(allowed_interface) + (interfaces.IPage, ))

    class_dict = dict(kwargs)
    class_dict['__name__'] = name

    if title is not None:
        class_dict['title'] = title
    if subtitle is not None:
        class_dict['subtitle'] = subtitle

    # XXX: raise ConfigurationError if class_ is Page and
    #      no templates specified

    templates = template_specs(
        {
            'template': template,
            'page_template': page_template,
            'content_template': content_template,
        },
        content_type='html')

    class_ = subclass_content(
        class_,
        name,
        forward_methods,
        templates,
        class_dict,
    )

    handle_interfaces(_context, (for_, ))
    handle_interfaces(_context, allowed_interface)

    handle_security(class_, permission, allowed_interface, allowed_attributes)

    _context.action(
        discriminator=('view', for_, name, IBrowserRequest, layer),
        callable=zope.component.zcml.handler,
        args=('registerAdapter', class_, (for_, layer), Interface, name,
              _context.info),
    )