Exemplo n.º 1
0
def get_meta(cls, method_name, context):
    """Get metadata dictionary for the method or class"""
    if not method_name:
        return meta_module.aggregate_meta(cls, context)

    method = cls.find_single_method(method_name)
    return meta_module.aggregate_meta(method, context)
Exemplo n.º 2
0
def list_model_builders(cls, context):
    """List model builder names of the class

    Yield names of all model builders (static actions marked with appropriate
    metadata) plus empty string for the class itself.
    """

    yield ''
    for method_name in cls.all_method_names:
        try:
            method = cls.find_single_method(method_name)
            if not method.is_action or not method.is_static:
                continue
            meta = meta_module.aggregate_meta(method, context)
            is_builder = meta.get('io.murano.metadata.ModelBuilder')
            if is_builder and is_builder.get_property('enabled'):
                yield method.name
        except Exception:
            pass
Exemplo n.º 3
0
def generate_ui_hints(entity, context, type_weights):
    """Translate know property/arg meta into json-schema UI hints"""
    schema = {}
    meta = meta_module.aggregate_meta(entity, context)
    for cls_name, schema_prop, meta_prop in (
        ('io.murano.metadata.Title', 'title',
         'text'), ('io.murano.metadata.Description', 'description', 'text'),
        ('io.murano.metadata.HelpText', 'helpText',
         'text'), ('io.murano.metadata.forms.Hidden', 'visible', 'visible')):
        value = meta.get(cls_name)
        if value is not None:
            schema[schema_prop] = value.get_property(meta_prop)

    position = meta.get('io.murano.metadata.forms.Position')
    if position:
        schema['formSection'] = position.get_property('section')
        index = position.get_property('index')
        if index is not None:
            schema['formIndex'] = (
                (position.get_property('index') + 1) * len(type_weights) -
                type_weights[position.declaring_type.name])

    return schema