예제 #1
0
    def get(self, cr, obj, ids, name, user=None, context=None, values=None):
        if not context:
            context = {}
        if not values:
            values = {}
        res = {}
        if self._method:
            res = self._fnct(obj, cr, user, ids, name, self._arg, context)
        else:
            res = self._fnct(cr, obj._table, ids, name, self._arg, context)

        if self._type == "many2one" :
            # Filtering only integer/long values if passed
            res_ids = [x for x in res.values() if x and isinstance(x, (int,long))]
            
            if res_ids:
                obj_model = obj.pool.get(self._obj)
                dict_names = dict(obj_model.name_get(cr, user, res_ids, context))
                for r in res.keys():
                    if res[r] and res[r] in dict_names:
                        res[r] = (res[r], dict_names[res[r]])
            
        if self._type == 'binary' and context.get('bin_size', False):
            # convert the data returned by the function with the size of that data...
            res = dict(map(lambda (x, y): (x, tools.human_size(len(y or ''))), res.items()))
        return res
예제 #2
0
def get_nice_size(a):
    (x,y) = a
    if isinstance(y, (int,long)):
        size = y
    elif y:
        size = len(y)
    else:
        size = 0
    return (x, tools.human_size(size))
예제 #3
0
 def set(self, model, value, modified=False):
     model.value[self.name] = value
     if value:
         value = tools.human_size(len(base64.b64decode(value)))
     model.value["%s.size" % self.name] = value
     if modified:
         model.modified = True
         model.modified_fields.setdefault(self.name)
     return True
예제 #4
0
 def set(self, model, value, test_state=True, modified=False, get_binary_size=True):
     self.__check_model(model)
     if model.is_wizard():
         get_binary_size = False
     model.value[self.name] = None
     name = get_binary_size and self.get_size_name() or self.name
     model.value[name] = value
     if (not get_binary_size) and value:
         model.value[self.get_size_name()] = tools.human_size(len(value))
     if not value:
         model.value[self.get_size_name()] = ""
     if modified:
         model.modified = True
         model.modified_fields.setdefault(self.name)
     return True
예제 #5
0
파일: fields.py 프로젝트: Buyanbat/XacCRM
 def get_memory(self, cr, obj, ids, name, user=None, context=None, values=None):
     if not context:
         context = {}
     if not values:
         values = []
     res = {}
     for i in ids:
         val = None
         for v in values:
             if v['id'] == i:
                 val = v[name]
                 break
         if context.get('bin_size', False) and val:
             res[i] = tools.human_size(long(val))
         else:
             res[i] = val
     return res
예제 #6
0
 def set(self,
         model,
         value,
         test_state=True,
         modified=False,
         get_binary_size=True):
     self.__check_model(model)
     if model.is_wizard():
         get_binary_size = False
     model.value[self.name] = None
     name = get_binary_size and self.get_size_name() or self.name
     model.value[name] = value
     if (not get_binary_size) and value:
         model.value[self.get_size_name()] = tools.human_size(len(value))
     if not value:
         model.value[self.get_size_name()] = ""
     if modified:
         model.modified = True
         model.modified_fields.setdefault(self.name)
     return True
예제 #7
0
    def get_memory(self, cr, obj, ids, name, user=None, context=None, values=None):
        if not context:
            context = {}
        if not values:
            values = []
        res = {}
        for i in ids:
            val = None
            for v in values:
                if v['id'] == i:
                    val = v[name]
                    break

            # If client is requesting only the size of the field, we return it instead
            # of the content. Presumably a separate request will be done to read the actual
            # content if it's needed at some point.
            # TODO: after 6.0 we should consider returning a dict with size and content instead of
            #       having an implicit convention for the value
            if val and context.get('bin_size_%s' % name, context.get('bin_size')):
                res[i] = tools.human_size(long(val))
            else:
                res[i] = val
        return res
예제 #8
0
 def get(self, cursor, obj, ids, name, user=None, offset=0, context=None,
         values=None):
     if not context:
         context = {}
     db = mdbpool.get_db()
     fs = gfs.GridFS(db, collection='fs')
     res = self.get_oids(cursor, obj, ids, name)
     for rid, oid in res.items():
         filename = self.get_filename(obj, rid, name)
         if oid:
             oid = ObjectId(oid)
             val = fs.get(oid).read()
             if context.get('bin_size', False) and val:
                 version = db.fs.files.find(
                     {'filename': filename},
                     {'uploadDate': True, '_id': False}
                 ).count()
                 res[rid] = '%s - v%s' % (human_size(val), version)
             else:
                 res[rid] = val
         else:
             res[rid] = False
     return res
예제 #9
0
 def get_memory(self,
                cr,
                obj,
                ids,
                name,
                user=None,
                context=None,
                values=None):
     if not context:
         context = {}
     if not values:
         values = []
     res = {}
     for i in ids:
         val = None
         for v in values:
             if v['id'] == i:
                 val = v[name]
                 break
         if context.get('bin_size', False) and val:
             res[i] = tools.human_size(long(val))
         else:
             res[i] = val
     return res