Example #1
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()
Example #2
0
File: value.py Project: f3at/feat
 def __eq__(self, other):
     if not IValueInfo.providedBy(other):
         return NotSupported
     other = IValueInfo(other)
     if self.value_type != other.value_type:
         return False
     if self.use_default != other.use_default:
         return False
     if self.use_default and (self._default != other.default):
         return False
     if IValueOptions.providedBy(self) != IValueOptions.providedBy(other):
         return False
     if IValueOptions.providedBy(self):
         other = IValueOptions(other)
         other_options = set(other.iter_options())
         self_options = set(self.iter_options())
         if other_options != self_options:
             return False
         if self.is_restricted != other.is_restricted:
             return False
     if IValueRange.providedBy(self) != IValueRange.providedBy(other):
         return False
     if IValueRange.providedBy(self):
         other = IValueRange(other)
         if (self.minimum != other.minimum
             or self.maximum != other.maximum
             or self.increment != other.increment):
             return False
     return True
Example #3
0
    def _render_param_field(self, markup, context, param, nested_name=None):
        default = param.value_info.use_default and \
                  param.value_info.default

        label = param.label or param.value_info.label or param.name
        text_types = [ValueTypes.integer, ValueTypes.number,
                      ValueTypes.string]
        v_t = param.value_info.value_type
        input_name = '.'.join(filter(None, [nested_name, param.name]))
        if v_t in text_types:
            markup.label()(label).close()
            if IValueOptions.providedBy(param.value_info):
                options = IValueOptions(param.value_info)
                select = markup.select(name=input_name)
                for o in options.iter_options():
                    option = markup.option(value=o.value)(o.label).close()
                    if o.value == default:
                        option["selected"] = None
                select.close()
            else:
                extra = {}
                if default:
                    extra['value'] = default
                markup.input(type='text', name=input_name, **extra)
        elif v_t == ValueTypes.boolean:
            markup.label()(label).close()
            extra = {}
            if default is True:
                extra['checked'] = '1'
            markup.input(type='checkbox', value='true',
                         name=input_name, **extra)
        elif v_t == ValueTypes.struct:
            fieldset = markup.fieldset()
            markup.legend()(label).close()
            for field in param.value_info.fields:
                self._render_param_field(markup, context, field, input_name)
            fieldset.close()
        else:
            msg = ("ValueType %s is not supported by HTML writer" %
                   (v_t.name))
            markup.span(_class='type_not_supported')(msg).close()
        if param.desc:
            markup.span(_class='desc')(param.desc).close()
        if not param.is_required:
            markup.span(_class='optional')("Optional").close()
        markup.br()
Example #4
0
    def _render_param_field(self, markup, context, param):
        default = param.value_info.use_default and \
                  param.value_info.default

        label = param.label or param.value_info.label or param.name
        markup.label()(label).close()
        text_types = [ValueTypes.integer, ValueTypes.number,
                      ValueTypes.string]
        v_t = param.value_info.value_type
        if v_t in text_types:
            if IValueOptions.providedBy(param.value_info):
                options = IValueOptions(param.value_info)
                select = markup.select(name=param.name)
                for o in options.iter_options():
                    option = markup.option(value=o.value)(o.label).close()
                    if o.value == default:
                        option["selected"] = None
                select.close()
            else:
                markup.input(type='text', default=default,
                             name=param.name)
        elif v_t == ValueTypes.boolean:
            extra = {}
            if default is True:
                extra['checked'] = '1'
            markup.input(type='checkbox', value='true',
                         name=param.name, **extra)
        else:
            msg = ("ValueType %s is not supported by HTML writer" %
                   (v_t.__name__))
            markup.span(_class='type_not_supported')(msg)
        if param.desc:
            markup.span(_class='desc')(param.desc).close()
        if not param.is_required:
            markup.span(_class='optional')("Optional").close()
        markup.br()