Exemplo n.º 1
0
def register_new_custom_type(type_key, workflow_key, archetype_key):
    """Retrieve (create if needed) a domain interface and model for type_key,
    and register as new entry on TYPE_REGISTER.
    """
    
    # generate custom domain interface
    domain_iface_name = naming.model_interface_name(type_key)
    try:
        domain_iface = resolve("%s.%s" % (INTERFACE_MODULE.__name__, domain_iface_name))
        log.warn("Custom interface ALREADY EXISTS: %s" % (domain_iface))
    except ImportError:
        domain_iface = new_custom_domain_interface(type_key, domain_iface_name)
    
    # generate custom domain_model
    domain_model_name = naming.model_name(type_key)
    try:
        domain_model = resolve("%s.%s" % (MODEL_MODULE.__name__, domain_model_name))
        log.warn("Custom domain model ALREADY EXISTS: %s" % (domain_model))
    except ImportError:
        domain_model = new_custom_domain_model(type_key, domain_iface, archetype_key)
    
    # type_info entry
    ti = TI(workflow_key, domain_iface, domain_model)
    ti.custom = True
    TYPE_REGISTRY.append((type_key, ti))
    
    log.info("Registered custom type [%s]: %s" % (archetype_key, type_key))
    return type_key, ti
Exemplo n.º 2
0
def register_new_custom_type(type_key, workflow_key, archetype_key):
    """Retrieve (create if needed) a domain interface and model for type_key,
    and register as new entry on TYPE_REGISTER.
    """

    # generate custom domain interface
    domain_iface_name = naming.model_interface_name(type_key)
    try:
        domain_iface = resolve("%s.%s" %
                               (INTERFACE_MODULE.__name__, domain_iface_name))
        log.warn("Custom interface ALREADY EXISTS: %s" % (domain_iface))
    except ImportError:
        domain_iface = new_custom_domain_interface(type_key, domain_iface_name)

    # generate custom domain_model
    domain_model_name = naming.model_name(type_key)
    try:
        domain_model = resolve("%s.%s" %
                               (MODEL_MODULE.__name__, domain_model_name))
        log.warn("Custom domain model ALREADY EXISTS: %s" % (domain_model))
    except ImportError:
        domain_model = new_custom_domain_model(type_key, domain_iface,
                                               archetype_key)

    # type_info entry
    ti = TI(workflow_key, domain_iface, domain_model)
    ti.custom = True
    TYPE_REGISTRY.append((type_key, ti))

    log.info("Registered custom type [%s]: %s" % (archetype_key, type_key))
    return type_key, ti
Exemplo n.º 3
0
def register_new_custom_type(type_key, workflow_key, custom_archetype_key,
                             sys_archetype_key):
    """Retrieve (create if needed) a domain interface and model for type_key,
    and register as new entry on TYPE_REGISTER.
    """
    archetype_model = resolve(
        "%s.%s" %
        (MODEL_MODULE.__name__, naming.model_name(custom_archetype_key)))
    # validate that custom archetype uses correct system archetype
    if custom_archetype_key != sys_archetype_key:
        sys_archetype_model = resolve(
            "%s.%s" %
            (MODEL_MODULE.__name__, naming.model_name(sys_archetype_key)))
        assert issubclass(archetype_model, sys_archetype_model), \
            "Custom archetype %r for type %r is not a sub-type of %r." % (
                custom_archetype_key, type_key, sys_archetype_key)

    # generate custom domain interface
    domain_iface_name = naming.model_interface_name(type_key)
    try:
        domain_iface = resolve("%s.%s" %
                               (INTERFACE_MODULE.__name__, domain_iface_name))
        log.warn("Custom interface ALREADY EXISTS: %s" % (domain_iface))
    except ImportError:
        domain_iface = new_custom_domain_interface(type_key, domain_iface_name)

    # generate custom domain_model
    domain_model_name = naming.model_name(type_key)
    try:
        domain_model = resolve("%s.%s" %
                               (MODEL_MODULE.__name__, domain_model_name))
        log.warn("Custom domain model ALREADY EXISTS: %s" % (domain_model))
    except ImportError:
        domain_model = new_custom_domain_model(type_key, domain_iface,
                                               custom_archetype_key)

    # type_info entry
    ti = TI(workflow_key, domain_iface, domain_model, archetype_model)
    ti.custom = True
    TYPE_REGISTRY.append((type_key, ti))

    log.info("Registered custom type [%s]: %s" %
             (custom_archetype_key, type_key))
    return type_key, ti
Exemplo n.º 4
0
def register_new_custom_type(type_key, workflow_key, 
        custom_archetype_key, sys_archetype_key
    ):
    """Retrieve (create if needed) a domain interface and model for type_key,
    and register as new entry on TYPE_REGISTER.
    """
    archetype_model = resolve("%s.%s" % (
            MODEL_MODULE.__name__, naming.model_name(custom_archetype_key)))
    # validate that custom archetype uses correct system archetype
    if custom_archetype_key != sys_archetype_key:
        sys_archetype_model = resolve("%s.%s" % (
                MODEL_MODULE.__name__, naming.model_name(sys_archetype_key)))
        assert issubclass(archetype_model, sys_archetype_model), \
            "Custom archetype %r for type %r is not a sub-type of %r." % (
                custom_archetype_key, type_key, sys_archetype_key)
    
    # generate custom domain interface
    domain_iface_name = naming.model_interface_name(type_key)
    try:
        domain_iface = resolve("%s.%s" % (INTERFACE_MODULE.__name__, domain_iface_name))
        log.warn("Custom interface ALREADY EXISTS: %s" % (domain_iface))
    except ImportError:
        domain_iface = new_custom_domain_interface(type_key, domain_iface_name)
    
    # generate custom domain_model
    domain_model_name = naming.model_name(type_key)
    try:
        domain_model = resolve("%s.%s" % (MODEL_MODULE.__name__, domain_model_name))
        log.warn("Custom domain model ALREADY EXISTS: %s" % (domain_model))
    except ImportError:
        domain_model = new_custom_domain_model(type_key, domain_iface, custom_archetype_key)
    
    # type_info entry
    ti = TI(workflow_key, domain_iface, domain_model, archetype_model)
    ti.custom = True
    TYPE_REGISTRY.append((type_key, ti))
    
    log.info("Registered custom type [%s]: %s" % (custom_archetype_key, type_key))
    return type_key, ti
Exemplo n.º 5
0
def register_new_custom_type(type_key, sys_archetype_key, custom_archetype_key,
                             workflow_key, descriptor_key, label,
                             container_label):
    """Retrieve (create if needed) a domain interface and model for type_key,
    and register as new entry on TYPE_REGISTER.
    """
    if custom_archetype_key is None:
        custom_archetype_key = sys_archetype_key
    archetype_model = resolve(
        "%s.%s" %
        (MODEL_MODULE.__name__, naming.model_name(custom_archetype_key)))
    # validate that custom archetype uses correct system archetype
    if custom_archetype_key != sys_archetype_key:
        sys_archetype_model = resolve(
            "%s.%s" %
            (MODEL_MODULE.__name__, naming.model_name(sys_archetype_key)))
        assert issubclass(archetype_model, sys_archetype_model), \
            "Custom archetype %r for type %r is not a sub-type of %r." % (
                custom_archetype_key, type_key, sys_archetype_key)

    # generate custom domain interface
    domain_iface_name = naming.model_interface_name(type_key)
    try:
        domain_iface = resolve("%s.%s" %
                               (INTERFACE_MODULE.__name__, domain_iface_name))
        log.warn("Custom interface ALREADY EXISTS: %s", domain_iface)
    except ImportError:
        domain_iface = new_custom_domain_interface(type_key, domain_iface_name,
                                                   archetype_model)

    # generate custom domain_model
    domain_model_name = naming.model_name(type_key)
    try:
        domain_model = resolve("%s.%s" %
                               (MODEL_MODULE.__name__, domain_model_name))
        log.warn("Custom domain model ALREADY EXISTS: %s", domain_model)
    except ImportError:
        domain_model = new_custom_domain_model(type_key, domain_iface,
                                               custom_archetype_key)

    if workflow_key is None:
        workflow_key = type_key
    if descriptor_key is None:
        descriptor_key = type_key

    # ILegislativeContent === sys_archetype_key=="doc"
    # Provide convenience marker to easily distinguish between
    # "system super archetype" and "system sub archetype", specifically
    # between Doc and Event, i.e. we want to mark all types implementing
    # IDoc but not IEvent (that also always implement IDoc).
    if sys_archetype_key == "doc":
        if not interfaces.ILegislativeContent.implementedBy(domain_model):
            classImplements(domain_model, interfaces.ILegislativeContent)

    # !+MENUITEM_TITLE check uniqueness constraint on type labels -- due to
    # zope.componenet registration issues on registering multiple menuitems on
    # same (interface, title) pairs, may be changed in future... possible
    # alternative is to infer a sub-interface to distinguish between "same" pairs
    if label is not None:
        for tk, ti in _iter():
            assert not label == ti.label, \
                "Label %r for custom type %r is not unique (see type %r)" % (
                    label, type_key, tk)

    # type_info entry
    ti = TI(type_key, workflow_key, domain_iface, domain_model,
            archetype_model)
    ti.descriptor_key = descriptor_key
    ti.label = label
    ti.container_label = container_label
    ti.custom = True
    ti.custom_archetype_key = custom_archetype_key
    ti.sys_archetype_key = sys_archetype_key
    TYPE_REGISTRY.append(ti)

    log.info("Registered custom type [%s]: %s", custom_archetype_key, type_key)
    return type_key, ti
Exemplo n.º 6
0
def register_new_custom_type(type_key, sys_archetype_key, custom_archetype_key, 
        workflow_key, descriptor_key,
        label, container_label
    ):
    """Retrieve (create if needed) a domain interface and model for type_key,
    and register as new entry on TYPE_REGISTER.
    """
    if custom_archetype_key is None:
        custom_archetype_key = sys_archetype_key
    archetype_model = resolve("%s.%s" % (
            MODEL_MODULE.__name__, naming.model_name(custom_archetype_key)))
    # validate that custom archetype uses correct system archetype
    if custom_archetype_key != sys_archetype_key:
        sys_archetype_model = resolve("%s.%s" % (
                MODEL_MODULE.__name__, naming.model_name(sys_archetype_key)))
        assert issubclass(archetype_model, sys_archetype_model), \
            "Custom archetype %r for type %r is not a sub-type of %r." % (
                custom_archetype_key, type_key, sys_archetype_key)
    
    # generate custom domain interface
    domain_iface_name = naming.model_interface_name(type_key)
    try:
        domain_iface = resolve("%s.%s" % (INTERFACE_MODULE.__name__, domain_iface_name))
        log.warn("Custom interface ALREADY EXISTS: %s", domain_iface)
    except ImportError:
        domain_iface = new_custom_domain_interface(type_key, domain_iface_name, archetype_model)
    
    # generate custom domain_model
    domain_model_name = naming.model_name(type_key)
    try:
        domain_model = resolve("%s.%s" % (MODEL_MODULE.__name__, domain_model_name))
        log.warn("Custom domain model ALREADY EXISTS: %s", domain_model)
    except ImportError:
        domain_model = new_custom_domain_model(type_key, domain_iface, custom_archetype_key)
    
    if workflow_key is None:
        workflow_key = type_key
    if descriptor_key is None:
        descriptor_key = type_key    
    
    # ILegislativeContent === sys_archetype_key=="doc"
    # Provide convenience marker to easily distinguish between 
    # "system super archetype" and "system sub archetype", specifically 
    # between Doc and Event, i.e. we want to mark all types implementing
    # IDoc but not IEvent (that also always implement IDoc).
    if sys_archetype_key == "doc":
        if not interfaces.ILegislativeContent.implementedBy(domain_model):
            classImplements(domain_model, interfaces.ILegislativeContent)
    
    # !+MENUITEM_TITLE check uniqueness constraint on type labels -- due to 
    # zope.componenet registration issues on registering multiple menuitems on 
    # same (interface, title) pairs, may be changed in future... possible 
    # alternative is to infer a sub-interface to distinguish between "same" pairs
    if label is not None:
        for tk, ti in _iter():
            assert not label == ti.label, \
                "Label %r for custom type %r is not unique (see type %r)" % (
                    label, type_key, tk)
    
    # type_info entry
    ti = TI(type_key, workflow_key, domain_iface, domain_model, archetype_model)
    ti.descriptor_key = descriptor_key
    ti.label = label
    ti.container_label = container_label
    ti.custom = True
    ti.custom_archetype_key = custom_archetype_key
    ti.sys_archetype_key = sys_archetype_key
    TYPE_REGISTRY.append(ti)
    
    log.info("Registered custom type [%s]: %s", custom_archetype_key, type_key)
    return type_key, ti