def parse_spec(spec, keys=None):
        if keys is None:
            keys = []
        if not isinstance(keys, list):
            keys = [keys]
        key = keys and keys[-1] or None

        if isinstance(spec, yaql_expression.YaqlExpression):
            return key, fields.RawProperty(key, spec)
        elif isinstance(spec, dict):
            items = []
            for k, v in six.iteritems(spec):
                k = helpers.decamelize(k)
                new_key, v = parse_spec(v, keys + [k])
                if new_key:
                    k = new_key
                items.append((k, v))
            return key, dict(items)
        elif isinstance(spec, list):
            return key, [parse_spec(_spec, keys)[1] for _spec in spec]
        elif isinstance(spec,
                        six.string_types) and helpers.is_localizable(keys):
            return key, spec
        else:
            if key == 'hidden':
                if spec:
                    return 'widget', forms.HiddenInput
                else:
                    return 'widget', None
            elif key == 'regexp_validator':
                return 'validators', [helpers.prepare_regexp(spec)]
            else:
                return key, spec
Beispiel #2
0
    def parse_spec(spec, keys=None):
        if keys is None:
            keys = []

        if not isinstance(keys, types.ListType):
            keys = [keys]
        key = keys and keys[-1] or None
        if isinstance(spec, yaql_expression.YaqlExpression):
            return key, fields.RawProperty(key, spec)
        elif isinstance(spec, types.DictType):
            items = []
            for k, v in spec.iteritems():
                if not k in ('type', 'name'):
                    k = helpers.decamelize(k)
                    new_key, v = parse_spec(v, keys + [k])
                    if new_key:
                        k = new_key
                    items.append((k, v))
            return key, dict(items)
        elif isinstance(spec, types.ListType):
            return key, [parse_spec(_spec, keys)[1] for _spec in spec]
        elif isinstance(spec, basestring) and helpers.is_localizable(keys):
            return key, _(spec)
        else:
            if key == 'type':
                return key, TYPES[spec]
            elif key == 'hidden' and spec is True:
                return 'widget', forms.HiddenInput
            elif key == 'regexp_validator':
                return 'validators', [helpers.prepare_regexp(spec)]
            else:
                return key, spec