Esempio n. 1
0
def registerConfiglet(name=None,schema=None,klass=None,title='',description=''):
    if '.' in name:
        category, name = name.split('.', 1)
    else:
        raise ValueError("Category name is required.")

    def _register(name, category, schema, klass, title, description):
        ConfigletClass = configlettype.ConfigletType(
            str(name), schema, klass, title, description)
        interface.classImplements(ConfigletClass, schema)

        # register behavior for configlet
        bname = 'memphis.controlpanel-%s'%name

        # behavior
        bfactory = configlet.BehaviorFactory(name, bname)
        storage.registerBehavior(
            bname, schema, bfactory, schema = IConfigletData,
            title=title, description=description, configContext=None)

        # set additional attributes
        ConfigletClass.__category__ = category

        # configlet instance
        inst = ConfigletClass()

        # register configlet as utility
        config.registerUtility(inst, schema, '')

        # register configlet in control panel
        getUtility(IControlPanel).addConfiglet(inst)
        inst.__behavior__ = storage.getBehavior(schema)

    # add config action
    if immediately:
        _register(name, category, schema, klass, title, description)

    frame = sys._getframe(1)

    config.action.store.set(
        frame.f_locals, config.action,
        (_register, (name, category, schema, klass, title, description),
         {'discriminator': ('controlpanel:configlet', category, name)},
         config.getInfo()))

    del frame
Esempio n. 2
0
def registerField(name, field, title='', description=''):
    def _registerField(name, field, title, description):
        info = FieldInformation(name, field, title, description)
        config.registerAdapter(
            info, (IFieldMarker,), 
            IFieldInformation, name, configContext=None)
        config.registerAdapter(
            info.getInfo, (interface.implementedBy(field),), 
            IFieldInformation, configContext=None)

    frame = sys._getframe(1)

    config.action.store.set(
        frame.f_locals, config.action,
        (_registerField, (name, field, title, description),
         {'discriminator': ('memphis.schema:registerField', name)},
         config.getInfo()))

    del frame
Esempio n. 3
0
def registerCategory(name, marker=None, title='', description='',):
    def _register(name, marker, title, description):
        category = configlet.ConfigletCategory(name, title, description)

        if marker is not None:
            interface.directlyProvides(category, marker)

        getUtility(IControlPanel).addCategory(category)

    if immediately:
        _register(name, marker, title, description)

    # add config action
    frame = sys._getframe(1)

    config.action.store.set(
        frame.f_locals, config.action,
        (_register, (name, marker, title, description),
         {'discriminator': ('controlpanel:category', name)},
         config.getInfo()))

    del frame
Esempio n. 4
0
def registerType(
    name,
    behavior = 'content.instance',
    factory = Instance,
    schemas = (),
    behaviors = (),
    title = '',
    description = '', 
    global_allow = True, 
    permission = 'View', 
    actions = None,
    **kw):

    if name in registered:
        raise ValueError('Content type "%s" already registered.'%name)

    if not title:
        title = name

    if 'add_view_expr' not in kw:
        kw['add_view_expr'] = 'string:${object_url}/++content++%s'%name

    if 'icon_expr' not in kw:
        kw['icon_expr'] = 'string:${portal_url}/document_icon.png'

    if actions is None:
        actions = (
            {'id': 'view',
             'title': 'View',
             'action': 'string:${object_url}',
             'visible': True,
             'permissions': ('View',)},
            {'id': 'edit',
             'title': 'Edit',
             'action': 'string:${object_url}/edit.html',
             'visible': True,
             'permissions': ('Modify portal content',)},
            )

    ti = ContentType(
        behavior, name, factory, 
        behaviors = behaviors,
        schemas = schemas,
        title = title,
        description = description,
        content_meta_type = name,
        global_allow = global_allow,
        permission = permission,
        actions = actions,
        **kw)

    registered[name] = ti

    def completeRegistration():
        config.registerUtility(ti, ITypeInformation, name)

        # register zope2 meta_type
        info = {'name': name,
                'action': '',
                'product': 'memphis.content',
                'permission': permission,
                'visibility': 'Global',
                'interfaces': interface.Interface,
                'instance': None,
                'container_filter': None}

        meta_types = getattr(Products, 'meta_types', ())
        meta_types += (info,)
        Products.meta_types = meta_types

        ti._complete()

    frame = sys._getframe(1)

    config.action(
        completeRegistration,
        __frame = frame,
        __info = config.getInfo(2),
        __discriminator = ('memphis.content:type', name),
        __order = (config.moduleNum(frame.f_locals['__name__']), 990))

    return ti