Пример #1
0
    def __init__(self, **attrs):
        super(ProgressBar, self).__init__(**attrs)

        if attrs.get('type2') is 'float':
            self.validator = validators.Float()
        else:
            self.validator = validators.Int()
Пример #2
0
    def _convert(self, form=True, safe=False):
        from openerp.widgets.form import OneToMany
        kw = {}
        for name, attrs in self.data.items():

            if not isinstance(attrs, dict):
                kw[name] = attrs
                continue

            kind = attrs.get('type', 'char')
            value = attrs.get('value')

            required = attrs.get('required', False)

            if kind == "one2many":
                try:
                    o2m_ids = eval(value)
                    if o2m_ids:
                        if not isinstance(o2m_ids, list):
                            o2m_ids = [o2m_ids]

                        from openerp.utils import rpc
                        Relation = rpc.RPCProxy(attrs['relation'])
                        relation_objects = Relation.read(o2m_ids, [], rpc.session.context)
                        relation_fields = Relation.fields_get(False, rpc.session.context)
                        for relation_record in relation_objects:
                            for field_name, field_value in relation_record.items():
                                if field_name in relation_fields and relation_fields[field_name]['type'] == 'many2many':
                                    relation_record[field_name] = [OneToMany.replace_all(*field_value)]

                        value = []
                        for relation_record in relation_objects:
                            id = relation_record.pop('id')
                            value.append(OneToMany.update(id, relation_record))
                    else:
                        value = []
                except:
                    pass

            elif kind not in _VALIDATORS:
                kind = 'char'

            v = _VALIDATORS.get(kind, openobject.validators.DefaultValidator)()
            if kind == "float" and attrs.get("digit"):
                v = validators.Float(digit=attrs.get("digit"))
            v.not_empty = (required or False) and True

            try:
                if form:
                    converted = v.to_python(value, None)
                else:
                    converted = v.from_python(value, None)
                kw[name] = converted
            except formencode.api.Invalid, e:
                if form and not safe:
                    raise TinyFormError(name.replace('_terp_form/', ''), e.msg, e.value)
Пример #3
0
    def __init__(self, **attrs):
        super(Float, self).__init__(**attrs)

        digits = attrs.get('digits', (16,2))
        if isinstance(digits, basestring):
            digits = eval(digits)

        integer, digit = digits

        self.validator = validators.Float(digit=digit)
Пример #4
0
                v = v.make_dict()
            res[k] = v
        return res

    def __getstate__(self):
        return self.__dict__

    def __setstate__(self, d):
        self.__dict__.update(d)

_VALIDATORS = {
    'date': lambda *a: validators.DateTime(kind="date"),
    'time': lambda *a: validators.DateTime(kind="time"),
    'datetime': lambda *a: validators.DateTime(kind="datetime"),
    'float_time': lambda *a: validators.FloatTime(),
    'float': lambda *a: validators.Float(),
    'integer': lambda *a: validators.Int(),
    'selection': lambda *a: validators.Selection(),
    'char': lambda *a: validators.String(),
    'boolean': lambda *a: validators.Bool(),
    'reference': lambda *a: validators.Reference(),
    'binary': lambda *a: validators.Binary(),
    'text': lambda *a: validators.String(),
    'text_tag': lambda *a: validators.String(),
    'many2many': lambda *a: validators.many2many(),
    'one2many': lambda *a: validators.one2many(),
    'many2one': lambda *a: validators.many2one(),
    'email' : lambda *a: validators.Email(),
    'url' : lambda *a: validators.URL(),
    'picture': lambda *a: validators.Binary(),
}
Пример #5
0
    def _convert(self, form=True, safe=False):

        kw = {}
        for name, attrs in self.data.items():

            if not isinstance(attrs, dict):
                kw[name] = attrs
                continue

            kind = attrs.get('type', 'char')
            value = attrs.get('value')

            required = attrs.get('required', False)

            if kind == "one2many":
                try:
                    value = eval(value)
                    if value:
                        if not isinstance(value, list):
                            value = [value]
                        from openerp import rpc
                        proxy = rpc.RPCProxy(attrs['relation'])
                        res = proxy.read(value, [], rpc.session.context)
                        res1 = proxy.fields_get(False, rpc.session.context)
                        for values in res:
                            for key, val in values.items():
                                if key in res1.keys():
                                    if res1[key]['type'] == 'many2many':
                                        if val == []:
                                            values[key] = [(6, 0, [])]
                                        else:
                                            values[key] = [(6, 0, val)]
                        value = []
                        for r in res:
                            id = r.pop('id')
                            value += [(1, id, r)]
                    else:
                        value = []
                except:
                    pass

            elif kind not in _VALIDATORS:
                kind = 'char'

            v = _VALIDATORS.get(kind, validators.DefaultValidator)()
            if kind == "float" and attrs.get("digit"):
                v = validators.Float(digit=attrs.get("digit"))
            v.not_empty = (required or False) and True

            try:
                if form:
                    value = v.to_python(value, None)
                else:
                    value = v.from_python(value, None)

            except validators.Invalid, e:
                if form and not safe:
                    raise TinyFormError(name.replace('_terp_form/', ''), e.msg,
                                        e.value)

            kw[name] = value