From dc4c8df7aac81b5d68e40c1327fb362790cde70d Mon Sep 17 00:00:00 2001 From: Sambhav Satija Date: Mon, 26 Oct 2015 04:35:03 +0530 Subject: [PATCH] Renamed filesizeformat tag's bytes variable to avoid clash with builtin. --- django/template/defaultfilters.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 5564ee6fcc..02ecb34828 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -839,13 +839,13 @@ def yesno(value, arg=None): ################### @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, 102 bytes, etc). """ try: - bytes = float(bytes) + bytes_ = float(bytes_) except (TypeError, ValueError, UnicodeDecodeError): value = ungettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0} return avoid_wrapping(value) @@ -858,22 +858,22 @@ def filesizeformat(bytes): TB = 1 << 40 PB = 1 << 50 - negative = bytes < 0 + negative = bytes_ < 0 if negative: - bytes = -bytes # Allow formatting of negative numbers. + bytes_ = -bytes_ # Allow formatting of negative numbers. - if bytes < KB: - value = ungettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': bytes} - elif bytes < MB: - value = ugettext("%s KB") % filesize_number_format(bytes / KB) - elif bytes < GB: - value = ugettext("%s MB") % filesize_number_format(bytes / MB) - elif bytes < TB: - value = ugettext("%s GB") % filesize_number_format(bytes / GB) - elif bytes < PB: - value = ugettext("%s TB") % filesize_number_format(bytes / TB) + if bytes_ < KB: + value = ungettext("%(size)d byte", "%(size)d bytes", bytes_) % {'size': bytes_} + elif bytes_ < MB: + value = ugettext("%s KB") % filesize_number_format(bytes_ / KB) + elif bytes_ < GB: + value = ugettext("%s MB") % filesize_number_format(bytes_ / MB) + elif bytes_ < TB: + value = ugettext("%s GB") % filesize_number_format(bytes_ / GB) + elif bytes_ < PB: + value = ugettext("%s TB") % filesize_number_format(bytes_ / TB) else: - value = ugettext("%s PB") % filesize_number_format(bytes / PB) + value = ugettext("%s PB") % filesize_number_format(bytes_ / PB) if negative: value = "-%s" % value