Example #1
0
def registerComponent(_context, name, component, viewlet, manager, 
                      selection=None, image=None, permission="zope.Public"):
    """ Register a component to be used by articles
    """
    adapter(_context, [component], interfaces.IComponent, name=name, for_=[interfaces.IArticle])
    if selection:
        adapter(_context, [component], interfaces.IComponentSelection, name=name, for_=[selection])
        
    viewletDirective(_context, component.viewlet, permission, for_=component.interface, manager=manager, class_=viewlet, view=interfaces.IArticleView)

    if not image:
        path = os.path.abspath(str(_context.path(component.image.replace('++resource++', ''))))
        if os.path.isfile(path):
            image = path
    if image:
        resource(_context, component.image.replace('++resource++', ''), image=image)
Example #2
0
def registerCustomization(_context, **kwargs):
    """Register a customization.
    """
    name = str(kwargs.get('order', 10))

    if 'image' in kwargs:
        image_path = kwargs['image']
        basename, ext = os.path.splitext(os.path.basename(image_path))
        resourcename = 'inflator-%s-%s%s' % (basename, name, ext)
        resource(_context, resourcename, file=image_path)
        kwargs['image'] = '++resource++%s' % resourcename.encode('utf-8')

    component = InflatorCustomization(**kwargs)
    provides = IInflatorCustomization

    _context.action(
        discriminator=('bundle', name),
        callable=handler,
        args=('registerUtility', component, provides, name))