[FIX] osv: binary size already in human format
In version 8.0, postgresql's pg_size_pretty function is used (http://www.postgresql.org/docs/9.4/static/functions-admin.html) when getting the size of a binary field when reading if `bin_size` or `bin_size_[col_name]` is set in the context. So in 8.0 the size of a binary field get units bytes, kB, MB, GB and TB which was not taken into account. e.g: '5.3 GB'. This fix uses the size of the string to choose to differenciate the two. e.g: '10000 bytes' (the longest size) will be returned directly, but for something longer the human size of the content length will be returned. There is a corner case if a file is shorter than 12 bytes but it is an enough of a small scenario with small implications that it is deemed acceptable. closes #7485 opw-644085master
parent
2de301df24
commit
e33baecfa3
|
@ -162,9 +162,6 @@ class ir_attachment(osv.osv):
|
|||
result[attach.id] = self._file_read(cr, uid, attach.store_fname, bin_size)
|
||||
else:
|
||||
result[attach.id] = attach.db_datas
|
||||
if bin_size:
|
||||
result[attach.id] = int(result[attach.id] or 0)
|
||||
|
||||
return result
|
||||
|
||||
def _data_set(self, cr, uid, id, name, value, arg, context=None):
|
||||
|
|
|
@ -1069,6 +1069,8 @@ def get_nice_size(value):
|
|||
size = value
|
||||
elif value: # this is supposed to be a string
|
||||
size = len(value)
|
||||
if size < 12: # suppose human size
|
||||
return value
|
||||
return tools.human_size(size)
|
||||
|
||||
# See http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char
|
||||
|
|
Loading…
Reference in New Issue