Renamed filesizeformat tag's bytes variable to avoid clash with builtin.
This commit is contained in:
parent
ce7dd1273e
commit
dc4c8df7aa
|
@ -839,13 +839,13 @@ def yesno(value, arg=None):
|
||||||
###################
|
###################
|
||||||
|
|
||||||
@register.filter(is_safe=True)
|
@register.filter(is_safe=True)
|
||||||
def filesizeformat(bytes):
|
def filesizeformat(bytes_):
|
||||||
"""
|
"""
|
||||||
Formats the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB,
|
Formats the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB,
|
||||||
102 bytes, etc).
|
102 bytes, etc).
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
bytes = float(bytes)
|
bytes_ = float(bytes_)
|
||||||
except (TypeError, ValueError, UnicodeDecodeError):
|
except (TypeError, ValueError, UnicodeDecodeError):
|
||||||
value = ungettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0}
|
value = ungettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0}
|
||||||
return avoid_wrapping(value)
|
return avoid_wrapping(value)
|
||||||
|
@ -858,22 +858,22 @@ def filesizeformat(bytes):
|
||||||
TB = 1 << 40
|
TB = 1 << 40
|
||||||
PB = 1 << 50
|
PB = 1 << 50
|
||||||
|
|
||||||
negative = bytes < 0
|
negative = bytes_ < 0
|
||||||
if negative:
|
if negative:
|
||||||
bytes = -bytes # Allow formatting of negative numbers.
|
bytes_ = -bytes_ # Allow formatting of negative numbers.
|
||||||
|
|
||||||
if bytes < KB:
|
if bytes_ < KB:
|
||||||
value = ungettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': bytes}
|
value = ungettext("%(size)d byte", "%(size)d bytes", bytes_) % {'size': bytes_}
|
||||||
elif bytes < MB:
|
elif bytes_ < MB:
|
||||||
value = ugettext("%s KB") % filesize_number_format(bytes / KB)
|
value = ugettext("%s KB") % filesize_number_format(bytes_ / KB)
|
||||||
elif bytes < GB:
|
elif bytes_ < GB:
|
||||||
value = ugettext("%s MB") % filesize_number_format(bytes / MB)
|
value = ugettext("%s MB") % filesize_number_format(bytes_ / MB)
|
||||||
elif bytes < TB:
|
elif bytes_ < TB:
|
||||||
value = ugettext("%s GB") % filesize_number_format(bytes / GB)
|
value = ugettext("%s GB") % filesize_number_format(bytes_ / GB)
|
||||||
elif bytes < PB:
|
elif bytes_ < PB:
|
||||||
value = ugettext("%s TB") % filesize_number_format(bytes / TB)
|
value = ugettext("%s TB") % filesize_number_format(bytes_ / TB)
|
||||||
else:
|
else:
|
||||||
value = ugettext("%s PB") % filesize_number_format(bytes / PB)
|
value = ugettext("%s PB") % filesize_number_format(bytes_ / PB)
|
||||||
|
|
||||||
if negative:
|
if negative:
|
||||||
value = "-%s" % value
|
value = "-%s" % value
|
||||||
|
|
Loading…
Reference in New Issue