Author: russellm
Date: 2010-08-15 23:42:44 -0500 (Sun, 15 Aug 2010)
New Revision: 13594

Modified:
   django/trunk/django/template/defaultfilters.py
Log:
Fixed #14002 -- Modified filesize filter to ensure strings are translatable. 
Thanks to claudep for the report.

Modified: django/trunk/django/template/defaultfilters.py
===================================================================
--- django/trunk/django/template/defaultfilters.py      2010-08-15 22:02:04 UTC 
(rev 13593)
+++ django/trunk/django/template/defaultfilters.py      2010-08-16 04:42:44 UTC 
(rev 13594)
@@ -807,19 +807,17 @@
     except (TypeError,ValueError,UnicodeDecodeError):
         return u"0 bytes"
 
-    BYTE_UNITS = (
-        ('KB', 1024),
-        ('MB', 1024 * 1024),
-        ('GB', 1024 * 1024 * 1024),
-        ('TB', 1024 * 1024 * 1024 * 1024),
-        ('PB', 1024 * 1024 * 1024 * 1024 * 1024)
-    )
-
-    if bytes < BYTE_UNITS[0][1]:
+    if bytes < 1024:
         return ungettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': 
bytes}
-    for index, (unit, unit_size) in enumerate(BYTE_UNITS):
-        if bytes < unit_size * 1024 or index == len(BYTE_UNITS) - 1:
-            return ugettext("%.1f %s") % (bytes / unit_size, unit)
+    if bytes < 1024 * 1024:
+        return ugettext("%.1f KB") % (bytes / 1024)
+    if bytes < 1024 * 1024 * 1024:
+        return ugettext("%.1f MB") % (bytes / (1024 * 1024))
+    if bytes < 1024 * 1024 * 1024 * 1024:
+        return ugettext("%.1f GB") % (bytes / (1024 * 1024 * 1024))
+    if bytes < 1024 * 1024 * 1024 * 1024 * 1024:
+        return ugettext("%.1f TB") % (bytes / (1024 * 1024 * 1024 * 1024))
+    return ugettext("%.1f PB") % (bytes / (1024 * 1024 * 1024 * 1024 * 1024))
 filesizeformat.is_safe = True
 
 def pluralize(value, arg=u's'):

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to