From e3e4be1cfba8dc6e7d23142b7c95329fb7f5daa5 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Tue, 22 Sep 2009 12:30:46 +0300 Subject: [PATCH] [IMP]: allow binary function fields to directly return size. As used in document, function fields could have a shortcut method to return the size instead of the contents. If done so and return a number, use that instead. bzr revid: p_christ@hol.gr-20090922093046-9r0gsj0qenapi06o --- bin/osv/fields.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bin/osv/fields.py b/bin/osv/fields.py index d6d23f7af9d..0ca657e0ce7 100644 --- a/bin/osv/fields.py +++ b/bin/osv/fields.py @@ -583,6 +583,16 @@ class many2many(_column): obj.datas[id][name] = act[2] +def get_nice_size(a): + (x,y) = a + if isinstance(y, (int,long)): + size = y + elif y: + y = len(y) + else: + y = 0 + return (x, tools.human_size(size)) + # --------------------------------------------------------- # Function fields # --------------------------------------------------------- @@ -653,7 +663,7 @@ class function(_column): 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())) + res = dict(map( get_nice_size, res.items())) return res get_memory = get