Exemple #1
0
def render_param(param):
    result = AsyncDict()
    result.add("required", param.is_required)
    result.add("info", render_value_info(param.value_info))
    result.add_if_not_none("label", param.label)
    result.add_if_not_none("desc", param.desc)
    return result.wait()
Exemple #2
0
def render_value_info(value):
    result = AsyncDict()
    result.add("type", value.value_type.name)
    if value.use_default:
        result.add("default", value.default)
    result.add_if_not_none("label", value.label)
    result.add_if_not_none("desc", value.desc)
    result.add_if_true("metadata", render_metadata(value))
    if IEncodingInfo.providedBy(value):
        encinfo = IEncodingInfo(value)
        result.add_if_not_none("mimetype", encinfo.mime_type)
        result.add_if_not_none("encoding", encinfo.encoding)
    if IValueCollection.providedBy(value):
        coll = IValueCollection(value)
        allowed = [render_value_info(v) for v in coll.allowed_types]
        result.add("allowed", defer.join(*allowed))
        result.add("ordered", coll.is_ordered)
        result.add_if_not_none("min_size", coll.min_size)
        result.add_if_not_none("max_size", coll.max_size)
    if IValueRange.providedBy(value):
        vrange = IValueRange(value)
        result.add("minimum", vrange.minimum)
        result.add("maximum", vrange.maximum)
        result.add_if_not_none("increment", vrange.increment)
    if IValueOptions.providedBy(value):
        options = IValueOptions(value)
        result.add("restricted", options.is_restricted)
        result.add("options", [{"label": o.label, "value": o.value}
                               for o in options.iter_options()])
    return result.wait()
Exemple #3
0
def render_action(action, context):
    result = AsyncDict()
    result.add_if_not_none("label", action.label)
    result.add_if_not_none("desc", action.desc)
    result.add_if_true("metadata", render_metadata(action))
    result.add("method", context.get_action_method(action).name)
    result.add_if_true("idempotent", bool(action.is_idempotent))
    result.add("category", action.category.name)
    result.add_result("href", action.reference, "resolve", context)
    if action.result_info is not None:
        result.add("result", render_value_info(action.result_info))
    if action.parameters:
        result.add("params", render_params(action.parameters))
    return result.wait()
Exemple #4
0
def render_actions(actions, context):
    result = AsyncDict()
    for action in actions:
        result.add(action.name, render_action(action, context))
    return result.wait()
Exemple #5
0
def render_items(items, context):
    result = AsyncDict()
    for item in items:
        result.add(item.name, render_item(item, context))
    return result.wait()
Exemple #6
0
def render_params(params):
    result = AsyncDict()
    for param in params:
        result.add(param.name, render_param(param))
    return result.wait()