Ticket #14002: bigger-filesizeformat.diff
File bigger-filesizeformat.diff, 1.2 KB (added by , 14 years ago) |
---|
-
django/template/defaultfilters.py
803 803 except (TypeError,ValueError,UnicodeDecodeError): 804 804 return u"0 bytes" 805 805 806 if bytes < 1024: 806 BYTE_UNITS = ( 807 ('KB', 1024), 808 ('MB', 1024 * 1024), 809 ('GB', 1024 * 1024 * 1024), 810 ('TB', 1024 * 1024 * 1024 * 1024), 811 ('PB', 1024 * 1024 * 1024 * 1024 * 1024) 812 ) 813 814 if bytes < BYTE_UNITS[0][1]: 807 815 return ungettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': bytes} 808 if bytes < 1024 * 1024: 809 return ugettext("%.1f KB") % (bytes / 1024) 810 if bytes < 1024 * 1024 * 1024: 811 return ugettext("%.1f MB") % (bytes / (1024 * 1024)) 812 return ugettext("%.1f GB") % (bytes / (1024 * 1024 * 1024)) 816 for index, (unit, unit_size) in enumerate(BYTE_UNITS): 817 if bytes < unit_size * 1024 or index == len(BYTE_UNITS) - 1: 818 return ugettext("%.1f %s" % (bytes / unit_size, unit)) 813 819 filesizeformat.is_safe = True 814 820 815 821 def pluralize(value, arg=u's'):