Fixed #18645 -- Clarified filesizeformat implementation
Thanks Jérôme Renard for the patch.
This commit is contained in:
parent
810fd236fa
commit
1e89a208d0
|
@ -827,17 +827,23 @@ def filesizeformat(bytes):
|
||||||
|
|
||||||
filesize_number_format = lambda value: formats.number_format(round(value, 1), 1)
|
filesize_number_format = lambda value: formats.number_format(round(value, 1), 1)
|
||||||
|
|
||||||
if bytes < 1024:
|
KB = 1<<10
|
||||||
|
MB = 1<<20
|
||||||
|
GB = 1<<30
|
||||||
|
TB = 1<<40
|
||||||
|
PB = 1<<50
|
||||||
|
|
||||||
|
if bytes < KB:
|
||||||
return ungettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': bytes}
|
return ungettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': bytes}
|
||||||
if bytes < 1024 * 1024:
|
if bytes < MB:
|
||||||
return ugettext("%s KB") % filesize_number_format(bytes / 1024)
|
return ugettext("%s KB") % filesize_number_format(bytes / KB)
|
||||||
if bytes < 1024 * 1024 * 1024:
|
if bytes < GB:
|
||||||
return ugettext("%s MB") % filesize_number_format(bytes / (1024 * 1024))
|
return ugettext("%s MB") % filesize_number_format(bytes / MB)
|
||||||
if bytes < 1024 * 1024 * 1024 * 1024:
|
if bytes < TB:
|
||||||
return ugettext("%s GB") % filesize_number_format(bytes / (1024 * 1024 * 1024))
|
return ugettext("%s GB") % filesize_number_format(bytes / GB)
|
||||||
if bytes < 1024 * 1024 * 1024 * 1024 * 1024:
|
if bytes < PB:
|
||||||
return ugettext("%s TB") % filesize_number_format(bytes / (1024 * 1024 * 1024 * 1024))
|
return ugettext("%s TB") % filesize_number_format(bytes / TB)
|
||||||
return ugettext("%s PB") % filesize_number_format(bytes / (1024 * 1024 * 1024 * 1024 * 1024))
|
return ugettext("%s PB") % filesize_number_format(bytes / PB)
|
||||||
|
|
||||||
@register.filter(is_safe=False)
|
@register.filter(is_safe=False)
|
||||||
def pluralize(value, arg='s'):
|
def pluralize(value, arg='s'):
|
||||||
|
|
Loading…
Reference in New Issue