692
692
obj.datas[id][name] = act[2]
695
def get_nice_size(a):
697
if isinstance(y, (int,long)):
703
return (x, tools.human_size(size))
695
def get_nice_size(value):
697
if isinstance(value, (int,long)):
699
elif value: # this is supposed to be a string
701
return tools.human_size(size)
705
def sanitize_binary_value(dict_item):
703
def sanitize_binary_value(value):
706
704
# binary fields should be 7-bit ASCII base64-encoded data,
707
705
# but we do additional sanity checks to make sure the values
708
706
# are not something else that won't pass via xmlrpc
709
index, value = dict_item
710
707
if isinstance(value, (xmlrpclib.Binary, tuple, list, dict)):
711
708
# these builtin types are meant to pass untouched
714
711
# For all other cases, handle the value as a binary string:
715
712
# it could be a 7-bit ASCII string (e.g base64 data), but also
807
804
return self._fnct_search(obj, cr, uid, obj, name, args, context=context)
809
def get(self, cr, obj, ids, name, user=None, context=None, values=None):
806
def postprocess(self, cr, uid, obj, field, value=None, context=None):
810
807
if context is None:
816
res = self._fnct(obj, cr, user, ids, name, self._arg, context)
818
res = self._fnct(cr, obj._table, ids, name, self._arg, context)
820
if self._type == "many2one" :
821
# Filtering only integer/long values if passed
822
res_ids = [x for x in res.values() if x and isinstance(x, (int,long))]
825
obj_model = obj.pool.get(self._obj)
826
dict_names = dict(obj_model.name_get(cr, user, res_ids, context))
828
if res[r] and res[r] in dict_names:
829
res[r] = (res[r], dict_names[res[r]])
831
if self._type == 'binary':
810
field_type = obj._columns[field]._type
811
if field_type == "many2one":
812
# make the result a tuple if it is not already one
813
if isinstance(value, (int,long)) and hasattr(obj._columns[field], 'relation'):
814
obj_model = obj.pool.get(obj._columns[field].relation)
815
dict_names = dict(obj_model.name_get(cr, uid, [value], context))
816
result = (value, dict_names[value])
818
if field_type == 'binary':
832
819
if context.get('bin_size', False):
833
820
# client requests only the size of binary fields
834
res = dict(map(get_nice_size, res.items()))
821
result = get_nice_size(value)
836
res = dict(map(sanitize_binary_value, res.items()))
838
if self._type == "integer":
840
# Converting value into string so that it does not affect XML-RPC Limits
841
if isinstance(res[r],dict): # To treat integer values with _multi attribute
842
for record in res[r].keys():
843
res[r][record] = str(res[r][record])
823
result = sanitize_binary_value(value)
825
if field_type == "integer":
826
result = tools.ustr(value)
829
def get(self, cr, obj, ids, name, uid=False, context=None, values=None):
832
result = self._fnct(obj, cr, uid, ids, name, self._arg, context)
834
result = self._fnct(cr, obj._table, ids, name, self._arg, context)
836
if self._multi and id in result:
837
for field, value in result[id].iteritems():
839
result[id][field] = self.postprocess(cr, uid, obj, field, value, context)
841
result[id] = self.postprocess(cr, uid, obj, name, result[id], context)
849
846
def set(self, cr, obj, id, name, value, user=None, context=None):