summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2006-11-07 04:58:10 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2006-11-07 04:58:10 +0000
commit92151b2d283ee46dfaf35ec93c41ffabce58e850 (patch)
tree033542ce32262e7d36ebfc5137c1cfbd19fb510c
parentfebe05b9eff84ab1d1ec2af61f6cd8337422731a (diff)
Fixed #2914: filesizeformat no longer dies on invalid values. Thanks, dev@simon.net.nz
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4044 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/template/defaultfilters.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
index cf1d3d5f6d..969ef7b28b 100644
--- a/django/template/defaultfilters.py
+++ b/django/template/defaultfilters.py
@@ -421,7 +421,11 @@ def filesizeformat(bytes):
Format the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB, 102
bytes, etc).
"""
- bytes = float(bytes)
+ try:
+ bytes = float(bytes)
+ except TypeError:
+ return "0 bytes"
+
if bytes < 1024:
return "%d byte%s" % (bytes, bytes != 1 and 's' or '')
if bytes < 1024 * 1024: