Exemple #1
0
def directRouter(_context,
                 name,
                 class_,
                 namespace=None,
                 for_=Interface,
                 layer=IDefaultBrowserLayer,
                 timeout="180000",
                 permission='zenoss.Common'):

    # Register the view at which the class will be available
    page(_context, name, permission, for_, layer, class_=class_)

    # Make a viewlet class with the appropriate javascript source
    definition = DirectProviderDefinition(class_, name, timeout, namespace)

    source = definition.render()
    viewletclass = JavaScriptSourceViewlet(source)
    viewletDirective(_context,
                     name,
                     'zope2.Public',
                     for_,
                     layer,
                     manager=IExtDirectJavaScriptManager,
                     class_=viewletclass)

    jsonapi_source = definition.render_jsonapi()
    jsonapi_viewletclass = JavaScriptSourceViewlet(jsonapi_source)
    viewletDirective(_context,
                     name,
                     'zope2.Public',
                     for_,
                     layer,
                     manager=IJsonApiJavaScriptManager,
                     class_=jsonapi_viewletclass)
Exemple #2
0
def ViewDirective(_context,
                  name,
                  permission=None,
                  for_=Interface,
                  layer=IDefaultBrowserLayer,
                  template=None,
                  class_=None,
                  allowed_interface=None,
                  allowed_attributes=None,
                  attribute='__call__',
                  menu=None,
                  title=None):
    """ Daviz View Facet
    """
    if not name:
        raise TypeError("No name provided")

    label = title
    if title and not menu:
        title = None

    page(_context=_context,
         name=name,
         permission=permission,
         for_=for_,
         layer=layer,
         template=template,
         class_=class_,
         allowed_interface=allowed_interface,
         allowed_attributes=allowed_attributes,
         attribute=attribute,
         menu=menu,
         title=title)

    VisualizationFacets._views[name] = label or name
def directRouter(
    _context,
    name,
    class_,
    namespace=None,
    for_=Interface,
    layer=IDefaultBrowserLayer,
    timeout="180000",
    permission="zenoss.Common",
):

    # Register the view at which the class will be available
    page(_context, name, permission, for_, layer, class_=class_)

    # Make a viewlet class with the appropriate javascript source
    definition = DirectProviderDefinition(class_, name, timeout, namespace)

    source = definition.render()
    viewletclass = JavaScriptSourceViewlet(source)
    viewletDirective(
        _context, name, "zope2.Public", for_, layer, manager=IExtDirectJavaScriptManager, class_=viewletclass
    )

    jsonapi_source = definition.render_jsonapi()
    jsonapi_viewletclass = JavaScriptSourceViewlet(jsonapi_source)
    viewletDirective(
        _context, name, "zope2.Public", for_, layer, manager=IJsonApiJavaScriptManager, class_=jsonapi_viewletclass
    )

    # Create a mapping of all of the Zope routers for introspection
    allDirectRouters[class_] = dict(name=name, namespace=namespace, permission=permission)
Exemple #4
0
def ViewDirective(_context,
                  name,
                  permission,
                  for_=Interface,
                  layer=IDefaultBrowserLayer,
                  template=None,
                  class_=None,
                  allowed_interface=None,
                  allowed_attributes=None,
                  attribute='__call__',
                  menu=None,
                  title=None):
    """ Faceted view
    """
    label = title
    if title and not menu:
        title = None

    page(_context=_context,
         name=name,
         permission=permission,
         for_=for_,
         layer=layer,
         template=template,
         class_=class_,
         allowed_interface=allowed_interface,
         allowed_attributes=allowed_attributes,
         attribute=attribute,
         menu=menu,
         title=title)

    ViewsInfo._views[name] = label or name
Exemple #5
0
def WidgetDirective(_context,
                    name=u"progressbar.widget",
                    view=None,
                    edit=None,
                    permission=None,
                    edit_permission=None,
                    view_permission=None,
                    for_=Interface,
                    layer=IDefaultBrowserLayer):
    """ Progress bar widget
    """

    view_name = name + '.view'
    if not view_permission:
        view_permission = permission
    page(_context=_context,
         name=view_name,
         permission=view_permission,
         for_=for_,
         layer=layer,
         class_=view)

    ProgressbarWidgets._views[name] = name

    edit_name = name + '.edit'
    if not edit_permission:
        edit_permission = permission
    page(_context=_context,
         name=edit_name,
         permission=edit_permission,
         for_=for_,
         layer=layer,
         class_=edit)

    ProgressbarWidgets._edits[name] = name
def page_config(_context,
                name,
                permission,
                for_,
                layer=IDefaultBrowserLayer,
                template=None,
                class_=None,
                allowed_interface=None,
                allowed_attributes=None,
                attribute='__call__',
                menu=None,
                title=None,
                handler=None):

    if inspect.isfunction(handler):
        class_ = type(
            '{0:s}{1:s}'.format(str(uuid4()).replace('-', ''), str(name)),
            (BrowserViewCallable, ), {"_callable": staticmethod(handler)})
    elif inspect.isclass(handler):
        class_ = handler

    page(_context,
         name,
         permission,
         for_,
         layer=layer,
         template=template,
         class_=class_,
         allowed_interface=allowed_interface,
         allowed_attributes=allowed_attributes,
         attribute=attribute,
         menu=menu,
         title=title)
Exemple #7
0
def tile(_context, name,
            title=None, description=None, add_permission=None, schema=None,
            for_=None, layer=None, class_=None, template=None, permission=None):
    """Implements the <plone:tile /> directive
    """
    
    if title is not None or description is not None or add_permission is not None or schema is not None:
        if title is None or add_permission is None:
            raise ConfigurationError(u"When configuring a new type of tile, 'title' and 'add_permission' are required")
    
        type_ = TileType(name, title, add_permission, description, schema)
        
        utility(_context, provides=ITileType, component=type_, name=name)
    
    if for_ is not None or layer is not None or class_ is not None or template is not None or permission is not None:
        if class_ is None and template is None:
            raise ConfigurationError(u"When configuring a tile, 'class' or 'template' must be given.")
        if permission is None:
            raise ConfigurationError(u"When configuring a tile, 'permission' is required")
        
        if for_ is None:
            for_ = Interface
        if layer is None:
            layer = IDefaultBrowserLayer
        
        if class_ is None:
            class_ = Tile
            
        page(_context, name=name, permission=permission, for_=for_, layer=layer,
                template=template, class_=class_)
Exemple #8
0
    def execute(self, form, config, context, layer, name, permission, wrap):

        # Only grok if the context is an interface. We demand this so that the
        # form is more re-usable in case of type customisation.
        if not isinstance(context, zope.interface.interface.InterfaceClass):
            return False

        templates = form.module_info.getAnnotation('grok.templates', None)
        if templates is not None:
            config.action(discriminator=None,
                          callable=self.checkTemplates,
                          args=(templates, form.module_info, form))

        form.__view_name__ = name

        if wrap is None:
            wrap = DEFAULT_WRAP

        # Only use the wrapper view if we are on Zope < 2.12
        if wrap:
            factory = layout.wrap_form(form)
            factory.__view_name__ = name
        else:
            factory = form

        page(config,
             name=name,
             permission=permission,
             for_=context,
             layer=layer,
             class_=factory)

        return True
Exemple #9
0
def simple_view_directive(_context, handler, for_, name,
                          permission=_default_permission):
    class SimpleView(BrowserView):
        def __call__(self, **kwargs):
            context = self.aq_parent
            return handler(context, self.request, **kwargs)

    metaconfigure.page(_context, name, permission, for_, class_=SimpleView)
Exemple #10
0
def banner(_context, name, template, title, layer=IDefaultBrowserLayer):
    """
    Registers a banner template for use with CarouselBlock.
    """
    page(_context, name, 'zope.Public', ICarousel, layer=layer,
        template=template)
    menu = _context.resolve('zope.app.menus.carouselblock_bannertemplates')
    _handle_menu(_context, menu, title, 
        [ICarousel], name, 'zope.Public', layer)
Exemple #11
0
def pager(_context, name, template, title, layer=IDefaultBrowserLayer):
    """
    Registers a pager template for use with Carousel.
    """

    page(_context, name, "zope.Public", ICarousel, layer=layer, template=template)

    menu = _context.resolve("zope.app.menus.carousel_pagertemplates")
    _handle_menu(_context, menu, title, [ICarousel], name, "zope.Public", layer)
Exemple #12
0
def tile(_context,
         name,
         title=None,
         description=None,
         icon=None,
         add_permission=None,
         edit_permission=None,
         delete_permission=None,
         schema=None,
         for_=None,
         layer=None,
         class_=None,
         template=None,
         permission=None):
    """Implements the <plone:tile /> directive
    """
    if (title is not None or description is not None or icon is not None
            or add_permission is not None or schema is not None):
        if title is None or add_permission is None:
            raise ConfigurationError(
                u"When configuring a new type of tile, 'title' and "
                u"'add_permission' are required")
        type_ = TileType(name,
                         title,
                         add_permission,
                         permission,
                         edit_permission=edit_permission,
                         delete_permission=delete_permission,
                         description=description,
                         icon=icon,
                         schema=schema)

        utility(_context, provides=ITileType, component=type_, name=name)

    if (for_ is not None or layer is not None or class_ is not None
            or template is not None):
        if class_ is None and template is None:
            raise ConfigurationError(
                u"'class' or 'template' must be given when configuring a tile."
            )

        if for_ is None:
            for_ = Interface
        if layer is None:
            layer = IDefaultBrowserLayer

        if class_ is None:
            class_ = Tile

        page(_context,
             name=name,
             permission=permission,
             for_=for_,
             layer=layer,
             template=template,
             class_=class_)
Exemple #13
0
def simple_view_directive(_context,
                          handler,
                          for_,
                          name,
                          permission=_default_permission):
    class SimpleView(BrowserView):
        def __call__(self, **kwargs):
            context = self.aq_parent
            return handler(context, self.request, **kwargs)

    metaconfigure.page(_context, name, permission, for_, class_=SimpleView)
Exemple #14
0
def directRouter(_context, name, class_, namespace, timeout=None,
                 for_=Interface, layer=IDefaultBrowserLayer):

    # Register the view at which the class will be available
    page(_context, name, 'zope.Public', for_, layer, class_=class_)

    # Make a viewlet class with the appropriate javascript source
    source = DirectProviderDefinition(class_, name, namespace,
                                      timeout).render()
    viewletclass = JavaScriptSourceViewlet(source)

    viewletDirective(_context, name, 'zope.Public', for_, layer,
                     manager=IExtDirectJavaScriptManager, class_=viewletclass)
def register(_context, path):
    """ZCML directive handler"""

    if os.path.exists(path):
        for file_name in glob.glob(path+os.sep+'*.pt'):
            page(_context,
                 file_name.split(os.sep)[-1][:-3],
                 'zope2.View',
                 None,
                 template=file_name
                 )
    else:
        logger.error('PATH does not exist: %s'%path)
Exemple #16
0
def pager(_context, name, template, title, layer=IDefaultBrowserLayer):
    """
    Registers a pager template for use with Carousel.
    """

    page(_context,
         name,
         'zope.Public',
         ICarousel,
         layer=layer,
         template=template)

    menu = _context.resolve('zope.app.menus.carousel_pagertemplates')
    _handle_menu(_context, menu, title, [ICarousel], name, 'zope.Public',
                 layer)
def page_config(_context, name, permission, for_,
                layer=IDefaultBrowserLayer, template=None, class_=None,
                allowed_interface=None, allowed_attributes=None,
                attribute='__call__', menu=None, title=None, handler=None):

    if inspect.isfunction(handler):
        class_ = type('{0:s}{1:s}'.format(str(uuid4()).replace('-', ''),
                                          str(name)),
                      (BrowserViewCallable,),
                      {"_callable": staticmethod(handler)})
    elif inspect.isclass(handler):
        class_ = handler

    page(_context, name, permission, for_, layer=layer, template=template,
         class_=class_, allowed_interface=allowed_interface,
         allowed_attributes=allowed_attributes, attribute=attribute,
         menu=menu, title=title)
Exemple #18
0
def directRouter(_context, name, class_, namespace=None, for_=Interface,
                 layer=IDefaultBrowserLayer, timeout="180000", 
                 permission='zenoss.Common'):

    # Register the view at which the class will be available
    page(_context, name, permission, for_, layer, class_=class_)

    # Make a viewlet class with the appropriate javascript source
    definition = DirectProviderDefinition(class_, name, timeout, namespace)

    source = definition.render()
    viewletclass = JavaScriptSourceViewlet(source)
    viewletDirective(_context, name, 'zope2.Public', for_, layer, manager=IExtDirectJavaScriptManager, class_=viewletclass)

    jsonapi_source = definition.render_jsonapi()
    jsonapi_viewletclass = JavaScriptSourceViewlet(jsonapi_source)
    viewletDirective(_context, name, 'zope2.Public', for_, layer, manager=IJsonApiJavaScriptManager, class_=jsonapi_viewletclass)
def ViewDirective(_context, name, permission, for_=Interface,
                  layer=IDefaultBrowserLayer, template=None, class_=None,
                  allowed_interface=None, allowed_attributes=None,
                  attribute='__call__', menu=None, title=None):
    """ Faceted view
    """
    label = title
    if title and not menu:
        title = None

    page(_context=_context, name=name, permission=permission,
         for_=for_, layer=layer, template=template, class_=class_,
         allowed_interface=allowed_interface,
         allowed_attributes=allowed_attributes,
         attribute=attribute, menu=menu, title=title)

    ViewsInfo._views[name] = label or name
Exemple #20
0
def pagesFromDirectory(_context, directory, module, for_=None,
                       layer=IDefaultBrowserLayer, permission='zope.Public'):

    if isinstance(module, basestring):
        module = _context.resolve(module)

    _prefix = os.path.dirname(module.__file__)
    directory = os.path.join(_prefix, directory)

    if not os.path.isdir(directory):
        raise ConfigurationError(
            "Directory %s does not exist" % directory
            )

    for fname in glob.glob(os.path.join(directory, '*.pt')):
        name = os.path.splitext(os.path.basename(fname))[0]
        page(_context, name=name, permission=permission,
             layer=layer, for_=for_, template=fname)
def factory(_context, name, permission, for_,
            layer=IDefaultBrowserLayer,
            template=None, class_=None,
            allowed_interface=None, allowed_attributes=None,
            result_listing=None, sortable_fields=None,
            sort_string=None
            ):

    if class_ is None:
        class_ = search.SearchView

    from pkg_resources import resource_filename
    default_path = 'opencore.nui.main.search'

    if template is None:
        template = resource_filename(default_path,
                                     search.SearchView.default_template)
    if result_listing is None:
        result_listing = resource_filename(default_path, 
                                           search.SearchView.default_result_listing)
    if sortable_fields is None:
        sortable_fields = resource_filename(default_path,
                                            search.SearchView.default_sortable_fields)
    if sort_string is None:
        sort_string = resource_filename(default_path,
                                        search.SearchView.default_sort_string)

    if not os.path.isfile(result_listing):
        raise ConfigurationError("No such file", result_listing)

    if not os.path.isfile(sortable_fields):
        raise ConfigurationError("No such file", sortable_fields)

    if not os.path.isfile(sort_string):
        raise ConfigurationError("No such file", sort_string)

    setattr(class_, '_result_listing', ZopeTwoPageTemplateFile(result_listing))
    setattr(class_, '_sortable_fields', ZopeTwoPageTemplateFile(sortable_fields))
    setattr(class_, '_sort_string', ZopeTwoPageTemplateFile(sort_string))

    page(_context, name, permission, for_,
         layer=layer, template=template, class_=class_,
         allowed_interface=allowed_interface,
         allowed_attributes=allowed_attributes)         
def ViewDirective(_context, name, permission=None, for_=Interface,
                  layer=IDefaultBrowserLayer, template=None, class_=None,
                  allowed_interface=None, allowed_attributes=None,
                  attribute='__call__', menu=None, title=None):
    """ Daviz View
    """
    if not name:
        raise TypeError(_("No name provided"))

    label = title
    if title and not menu:
        title = None

    page(_context=_context, name=name, permission=permission,
         for_=for_, layer=layer, template=template, class_=class_,
         allowed_interface=allowed_interface,
         allowed_attributes=allowed_attributes,
         attribute=attribute, menu=menu, title=title)

    VisualizationViews._views[name] = label or name
def formControllerPage(
    _context, name, permission, for_, type_name,
    layer=browser.IDefaultBrowserLayer, template=None, class_=None,
    allowed_interface=None, allowed_attributes=None,
    attribute='__call__', menu=None, title=None):
    """Add the name to the class dict to make it accessible for
    looking up the template"""
    class_name = 'GeneratedFormControllerTemplateAddForm'
    bases = (at.FormControllerTemplateAddForm,)
    if class_ is not None:
        class_name = class_.__name__
        bases = (class_, at.FormControllerTemplateAddForm)
    class_ = metaclass.makeClass(
        class_name, bases, dict(name=name, type_name=type_name))
    metaconfigure.page(
        _context, name, permission, for_, layer=layer,
        template=template, class_=class_,
        allowed_interface=allowed_interface,
        allowed_attributes=allowed_attributes, attribute=attribute,
        menu=menu, title=title)
Exemple #24
0
def EditDirective(_context,
                  name,
                  permission=None,
                  for_=Interface,
                  layer=IDefaultBrowserLayer,
                  template=None,
                  class_=None,
                  allowed_interface=None,
                  allowed_attributes=None,
                  attribute='__call__',
                  menu=None,
                  title=None):
    """ Daviz Edit
    """
    if not name:
        raise TypeError(_("No name provided"))

    label = title
    if title and not menu:
        title = None

    if not name.endswith('.edit'):
        name += u'.edit'

    page(_context=_context,
         name=name,
         permission=permission,
         for_=for_,
         layer=layer,
         template=template,
         class_=class_,
         allowed_interface=allowed_interface,
         allowed_attributes=allowed_attributes,
         attribute=attribute,
         menu=menu,
         title=title)

    VisualizationViews._edits[name] = label or name
def EditDirective(_context, name, permission=None, for_=Interface,
                  layer=IDefaultBrowserLayer, template=None, class_=None,
                  allowed_interface=None, allowed_attributes=None,
                  attribute='__call__', menu=None, title=None):
    """ Daviz Edit Facet
    """
    if not name:
        raise TypeError("No name provided")

    label = title
    if title and not menu:
        title = None

    if not name.endswith('.edit'):
        name += u'.edit'

    page(_context=_context, name=name, permission=permission,
         for_=for_, layer=layer, template=template, class_=class_,
         allowed_interface=allowed_interface,
         allowed_attributes=allowed_attributes,
         attribute=attribute, menu=menu, title=title)

    VisualizationFacets._edits[name] = label or name
Exemple #26
0
    def execute(self, form, config, context, layer, name, permission, wrap):

        # Only grok if the context is an interface. We demand this so that the
        # form is more re-usable in case of type customisation.
        if not isinstance(context, zope.interface.interface.InterfaceClass):
            return False

        templates = form.module_info.getAnnotation('grok.templates', None)
        if templates is not None:
            config.action(
                discriminator=None,
                callable=self.checkTemplates,
                args=(templates, form.module_info, form)
                )

        form.__view_name__ = name

        if wrap is None:
            wrap = DEFAULT_WRAP

        # Only use the wrapper view if we are on Zope < 2.12
        if wrap:
            factory = layout.wrap_form(form)
            factory.__view_name__ = name
        else:
            factory = form

        page(
                config,
                name=name,
                permission=permission,
                for_=context,
                layer=layer,
                class_=factory
            )

        return True
Exemple #27
0
def portletDirective(_context, name, interface, assignment, renderer, addview,
        view_permission=u"zope2.View", edit_permission="plone.app.portlets.ManageOwnPortlets", editview=None):
    """Register a portlet assignment type using typical options.

    Portlets that consist of a simple assignment class deriving form
    base.Assignment, a renderer deriving from base.Renderer, an addview
    using formlib and deriving from base.AddForm and an editview (optional)
    using formlib and deriving from base.EditForm, can use this directive
    to avoid having to regiter each of those components individually.

    In addition, we register the portlet interface using IPortletTypeInterface
    and an IFactory utility, in order to help the GenericSetup handler and
    other generic code instantiate portlets.
    """

    name = str(name)  # De-unicode

    # Register the portlet interface as named utility so that we can find it
    # again (in the GS handler)

    alsoProvides(interface, IPortletTypeInterface)
    utility(_context,
            provides=IPortletTypeInterface,
            name=name,
            component=interface)

    # Register a factory

    utility(_context,
            provides=IFactory,
            name=name,
            component=Factory(assignment))

    # Set permissions on the assignment class

    # <class class="[assignment]">
    #   <require
    #       permission="[view_permission]"
    #       interface="[interface]"
    #       />
    # </class>

    # XXX: Is this necessary? The renderer doesn't need it, so it may
    # just be superfluous.

    # Register the renderer:

    # <adapter
    #   factory="[renderer]"
    #   for="zope.interface.Interface
    #        zope.publisher.interfaces.browser.IDefaultBrowserLayer
    #        zope.publisher.interfaces.browser.IBrowserView
    #        plone.portlets.interfaces.IPortletManager
    #        [interface]
    #   provides="plone.portlets.interfaces.IPortletRenderer"
    #   />

    adapter(_context, (renderer, ), provides=IPortletRenderer,
            for_=(Interface, IDefaultBrowserLayer, IBrowserView, IPortletManager, interface))
    _default_renderers[interface] = renderer

    # Register the adding view

    # <browser:page
    #   for="plone.app.portlets.browser.interfaces.IPortletAdding"
    #   name="[name]"
    #   class="[addview]"
    #   permission="[edit_permission]"
    #   />

    page(_context,
         for_=IPortletAdding,
         name=name,
         class_=addview,
         permission=edit_permission)

    # Register the edit view, if applicable

    # <browser:page
    #   for="[interface]"
    #   name="edit"
    #   class="[editview]"
    #   permission="[edit_permission]"
    #   />

    if editview is not None:
        page(_context,
             for_=interface,
             name="edit",
             class_=editview,
             permission=edit_permission)
Exemple #28
0
def portletDirective(_context,
                     name,
                     interface,
                     assignment,
                     renderer,
                     addview,
                     view_permission=u"zope2.View",
                     edit_permission="plone.app.portlets.ManageOwnPortlets",
                     editview=None):
    """Register a portlet assignment type using typical options.

    Portlets that consist of a simple assignment class deriving form
    base.Assignment, a renderer deriving from base.Renderer, an addview
    using z3c form and deriving from base.AddForm and an editview (optional)
    using z3c form and deriving from base.EditForm, can use this directive
    to avoid having to regiter each of those components individually.

    In addition, we register the portlet interface using IPortletTypeInterface
    and an IFactory utility, in order to help the GenericSetup handler and
    other generic code instantiate portlets.
    """

    name = str(name)  # De-unicode

    # Register the portlet interface as named utility so that we can find it
    # again (in the GS handler)

    alsoProvides(interface, IPortletTypeInterface)
    utility(_context,
            provides=IPortletTypeInterface,
            name=name,
            component=interface)

    # Register a factory

    utility(_context,
            provides=IFactory,
            name=name,
            component=Factory(assignment))

    # Set permissions on the assignment class

    # <class class="[assignment]">
    #   <require
    #       permission="[view_permission]"
    #       interface="[interface]"
    #       />
    # </class>

    # XXX: Is this necessary? The renderer doesn't need it, so it may
    # just be superfluous.

    # Register the renderer:

    # <adapter
    #   factory="[renderer]"
    #   for="zope.interface.Interface
    #        zope.publisher.interfaces.browser.IDefaultBrowserLayer
    #        zope.publisher.interfaces.browser.IBrowserView
    #        plone.portlets.interfaces.IPortletManager
    #        [interface]
    #   provides="plone.portlets.interfaces.IPortletRenderer"
    #   />

    adapter(_context, (renderer, ),
            provides=IPortletRenderer,
            for_=(Interface, IDefaultBrowserLayer, IBrowserView,
                  IPortletManager, interface))
    _default_renderers[interface] = renderer

    # Register the adding view

    # <browser:page
    #   for="plone.app.portlets.browser.interfaces.IPortletAdding"
    #   name="[name]"
    #   class="[addview]"
    #   permission="[edit_permission]"
    #   />

    page(_context,
         for_=IPortletAdding,
         name=name,
         class_=addview,
         permission=edit_permission)

    # Register the edit view, if applicable

    # <browser:page
    #   for="[interface]"
    #   name="edit"
    #   class="[editview]"
    #   permission="[edit_permission]"
    #   />

    if editview is not None:
        page(_context,
             for_=interface,
             name="edit",
             class_=editview,
             permission=edit_permission)