Ticket #8733: filesizeformat.patch
File filesizeformat.patch, 1.2 KB (added by , 16 years ago) |
---|
-
defaultfilters.py
725 725 726 726 def filesizeformat(bytes): 727 727 """ 728 Formats the value like a 'human-readable' file size (i.e. 13 K B, 4.1 MB,728 Formats the value like a 'human-readable' file size (i.e. 13 KiB, 4.1 MiB, 729 729 102 bytes, etc). 730 730 """ 731 731 try: … … 733 733 except TypeError: 734 734 return u"0 bytes" 735 735 736 if bytes < 1024 :736 if bytes < 1024 ** 1: 737 737 return ungettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': bytes} 738 if bytes < 1024 * 1024:739 return ugettext("%.1f K B") % (bytes / 1024)740 if bytes < 1024 * 1024 * 1024:741 return ugettext("%.1f M B") % (bytes / (1024 * 1024))742 return ugettext("%.1f G B") % (bytes / (1024 * 1024 * 1024))738 if bytes < 1024 ** 2: 739 return ugettext("%.1f KiB") % (bytes / (1024 ** 1)) 740 if bytes < 1024 ** 3: 741 return ugettext("%.1f MiB") % (bytes / (1024 ** 2)) 742 return ugettext("%.1f GiB") % (bytes / (1024 ** 3)) 743 743 filesizeformat.is_safe = True 744 744 745 745 def pluralize(value, arg=u's'):