Merge lp:~fabien-morin/unifield-web/fm-us-2110 into lp:unifield-web

Proposed by jftempo
Status: Merged
Merged at revision: 4832
Proposed branch: lp:~fabien-morin/unifield-web/fm-us-2110
Merge into: lp:unifield-web
Diff against target: 62 lines (+21/-12)
2 files modified
addons/openerp/utils/tools.py (+15/-12)
addons/openerp/widgets/listgrid.py (+6/-0)
To merge this branch: bzr merge lp:~fabien-morin/unifield-web/fm-us-2110
Reviewer Review Type Date Requested Status
UniField Dev Team Pending
Review via email: mp+314399@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/openerp/utils/tools.py'
2--- addons/openerp/utils/tools.py 2016-08-31 07:37:14 +0000
3+++ addons/openerp/utils/tools.py 2017-01-10 09:25:40 +0000
4@@ -206,21 +206,24 @@
5
6 return xp
7
8-def get_size(sz):
9+def get_size(data):
10 """
11 Return the size in a human readable format
12 """
13- if not sz:
14- return False
15-
16- units = ('bytes', 'Kb', 'Mb', 'Gb')
17- if isinstance(sz,basestring):
18- sz=len(sz)
19- s, i = float(sz), 0
20- while s >= 1024 and i < len(units)-1:
21- s = s / 1024
22- i = i + 1
23- return "%0.2f %s" % (s, units[i])
24+ units = ('Bytes', 'KB', 'MB', 'GB', 'TB')
25+ if isinstance(data, basestring):
26+ size = float(len(data))
27+ elif isinstance(data, (int, long)):
28+ size = float(data)
29+ elif isinstance(data, float):
30+ size = data
31+ else:
32+ return '0 Bytes'
33+ unit_index = 0
34+ while size >= 1024 and unit_index < len(units) - 1:
35+ size = size / 1024
36+ unit_index += 1
37+ return "%0.2f %s" % (size, units[unit_index])
38
39 def context_with_concurrency_info(context, concurrency_info):
40 ctx = (context or {})
41
42=== modified file 'addons/openerp/widgets/listgrid.py'
43--- addons/openerp/widgets/listgrid.py 2016-09-08 12:22:46 +0000
44+++ addons/openerp/widgets/listgrid.py 2017-01-10 09:25:40 +0000
45@@ -709,6 +709,11 @@
46 self.val = self.value
47 self.kind = 'text'
48
49+class HumanSize(Char):
50+
51+ def get_text(self):
52+ return utils.get_size(self.value or 0.0)
53+
54 class Button(TinyInputWidget):
55
56 params = ['icon', 'id', 'parent_grid', 'btype', 'confirm', 'width', 'context']
57@@ -802,4 +807,5 @@
58 'null_boolean' : NullBoolean,
59 'progressbar' : ProgressBar,
60 'separator': Separator,
61+ 'human_size': HumanSize,
62 }

Subscribers

People subscribed via source and target branches