1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #25441 -- Added support for negative filesize to filesizeformat template filter.

Thanks Andrey Yakovlev for the initial patch.
This commit is contained in:
Sambhav Satija
2015-10-25 07:21:20 +05:30
committed by Tim Graham
parent ea2f48ce8b
commit ce7dd1273e
2 changed files with 10 additions and 0 deletions

View File

@@ -858,6 +858,10 @@ def filesizeformat(bytes):
TB = 1 << 40
PB = 1 << 50
negative = bytes < 0
if negative:
bytes = -bytes # Allow formatting of negative numbers.
if bytes < KB:
value = ungettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': bytes}
elif bytes < MB:
@@ -871,6 +875,8 @@ def filesizeformat(bytes):
else:
value = ugettext("%s PB") % filesize_number_format(bytes / PB)
if negative:
value = "-%s" % value
return avoid_wrapping(value)