예제 #1
0
def registerBehavior(name, spec, factory, relation=None, schema=None,
                     type = None, title='', description = '', 
                     configContext=None, info=''):

    def _register(name,spec,factory,relation,schema,type,title,description):
        # check relation
        if relation:
            getRelation(relation)

        bh = Behavior(name, title, spec, relation, factory, schema, description)

        for tp in type:
            getSiteManager().registerUtility(bh, tp, name)

        # register in internal registry
        registry.registerBehavior(bh)

    if type is None:
        type = (IBehavior,)
    elif isinstance(type, InterfaceClass):
        type = (type,)

    config.addAction(
        configContext,
        ('memphis.storage:registerBehavior', name),
        callable= _register,
        args=(name, spec, factory, relation, schema, type, title, description),
        info=info)
예제 #2
0
def registerSchema(name, schema, klass=None, type=None,
                   title='', description='', configContext=None, info=''):

    def _register(name, schema, klass, type, title, description):
        sob = Schema(name, schema, klass, title, description)

        for tp in type:
            getSiteManager().registerUtility(sob, tp, name)

        # register in internal registry
        registry.registerSchema(sob)

        session = hooks.getSession()
        if session is not None:
            hooks.getMetadata().create_all()
            session.flush()

    if type is None:
        type = (ISchema,)
    elif isinstance(type, InterfaceClass):
        type = (type,)

    config.addAction(
        configContext,
        discriminator = ('memphis.storage:schema', name),
        callable=_register, args=(name,schema,klass,type,title, description),
        info = info)
예제 #3
0
파일: api.py 프로젝트: fafhrd91/memphis-dev
def registerPreference(name, schema, klass=None,
                       title='', description='', configContext=None):
    if '.' in name:
        category, name = name.split('.', 1)
    else:
        category = ''

    PreferenceClass = preferencetype.PreferenceType(
        str(name), category, schema, klass, title, description)

    # register storage schema
    if getFields(schema):
        storage.registerSchema(
            'memphis.preferences-%s.%s'%(category, name), schema)

    # instance
    inst = PreferenceClass()

    # register preference in preferences
    def _register(preference):
        root.Preferences.addPreference(preference)

    config.addAction(
        configContext,
        discriminator = ('memphis.preferences:preference', category, name),
        callable = _register, args = (inst,))

    return inst
예제 #4
0
파일: api.py 프로젝트: fafhrd91/memphis-dev
def registerCategory(name, title, description='', configContext=None):
    def _register(category):
        root.Preferences.addCategory(category)

    category = preference.PreferenceCategory(name, title, description)

    config.addAction(
        configContext,
        discriminator= ('memphis.preferences:category', name),
        callable = _register, args = (category,))

    return category
예제 #5
0
    def execute(self, factory, configContext=None, **kw):
        value = behavior.bind(default=_marker).get(factory)
        if value is _marker:
            return False

        name, iface, schema, type, t, d, info = value

        config.addAction(
            configContext,
            discriminator=("memphis.content:behavior", name),
            callable=registry.registerBehavior,
            args=(name, iface, factory(), schema, type, t, d),
            order=(config.moduleNum(factory.__module__), 91),
            info=info,
        )

        return True
예제 #6
0
    def grok(self, name, interface, configContext=config.UNSET, **kw):
        if interface in schemaExecuted and not getattr(interface.__module__, "__fake_module__", False):
            return False
        schemaExecuted.append(interface)

        value = schema.bind(default=_marker).get(interface)
        if value is _marker:
            return False

        name, klass, type, t, d, info = value

        config.addAction(
            configContext,
            discriminator=("memphis.content:schema", name),
            callable=registry.registerSchema,
            args=(name, interface, klass, type, t, d),
            order=(config.moduleNum(interface.__module__), 90),
            info=info,
        )
        return True
예제 #7
0
def initialize(engine, session, models=True):
    setSession(session)
    MetaData = getMetadata()
    MetaData.bind = engine

    if models:
        from memphis.storage.models import initializeModels

        initializeModels(MetaData)

    MetaData.create_all(engine)

    def _create():
        import zope.event
        from interfaces import StorageInitializedEvent
        zope.event.notify(StorageInitializedEvent(MetaData))

        session.flush()

    config.addAction(
        discriminator = ('memphis.storage:initialize',),
        callable=_create)
예제 #8
0
def registerRelation(name, schema, klass=None,
                     title='', description='', configContext=None, info=''):
    # fixme: remove this line
    from memphis.storage.relation import Relation, buildRelation

    def _register(name, schema, klass, title, description):
        if klass is not None:
            rel = Relation(name, klass, title, description)
        else:
            rel = buildRelation(name, schema, title, description)

        registry.registerRelation(rel, schema)

        # create table
        session = hooks.getSession()
        if session is not None:
            hooks.getMetadata().create_all()
            session.flush()

    config.addAction(
        configContext,
        discriminator = ('memphis.storage:relation', name),
        callable=_register, args=(name, schema, klass, title, description),
        info = info)
예제 #9
0
    def execute(self, klass, configContext=None, **kw):
        value = behavior.bind(default=_marker).get(klass)
        if value is _marker:
            return False

        name, iface, schema, type, t, d, info = value

        if iface is None:
            provides = list(interface.implementedBy(klass))
            if len(provides) == 1:
                iface = provides[0]
            else:
                raise TypeError("Missing 'spec' attribute")

        config.addAction(
            configContext,
            discriminator=("memphis.content:behavior", name),
            callable=registry.registerBehavior,
            args=(name, iface, klass, schema, type, t, d),
            order=(config.moduleNum(klass.__module__), 91),
            info=info,
        )

        return True