From 9886be592f6fd1ec5af91f7ef9de76e27d0e083f Mon Sep 17 00:00:00 2001 From: liaozd Date: Wed, 18 Jan 2017 00:20:04 +0800 Subject: [PATCH] filesizeformat() does't consider the situation like `float('inf')` Sometimes the `bytes` may get float('inf'), then it will display "inf0PB" which will be a misleading for the user. Besides, with the hardware like storage and MEM getting larger and larger, we should consider size larger than PB like EB, ZB and YB. Change-Id: I830ad440e9ef854006298bd946ab8ecf9d75757a Closes-Bug: 1657174 --- horizon/templatetags/sizeformat.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/horizon/templatetags/sizeformat.py b/horizon/templatetags/sizeformat.py index 06e00c628e..0068f6e34a 100644 --- a/horizon/templatetags/sizeformat.py +++ b/horizon/templatetags/sizeformat.py @@ -51,6 +51,8 @@ def filesizeformat(bytes, filesize_number_format): return ungettext_lazy("%(size)d Byte", "%(size)d Bytes", 0) % {'size': 0} + if bytes == float('inf'): + return _('Infinity') if bytes < units.Ki: bytes = int(bytes) return ungettext_lazy("%(size)d Byte", @@ -63,7 +65,13 @@ def filesizeformat(bytes, filesize_number_format): return _("%s GB") % filesize_number_format(bytes / units.Gi) if bytes < units.Pi: return _("%s TB") % filesize_number_format(bytes / units.Ti) - return _("%s PB") % filesize_number_format(bytes / units.Pi) + if bytes < units.Ei: + return _("%s PB") % filesize_number_format(bytes / units.Pi) + if bytes < units.Zi: + return _("%s EB") % filesize_number_format(bytes / units.Ei) + if bytes < units.Yi: + return _("%s ZB") % filesize_number_format(bytes / units.Zi) + return _("%s YB") % filesize_number_format(bytes / units.Yi) def float_cast_filesizeformat(value, multiplier=1, format=int_format):