Ticket #8733: filesizeformat.patch

File filesizeformat.patch, 1.2 KB (added by Florian Sening, 16 years ago)

Fixes filesizeformat so it will display the SI version of the value.

  • defaultfilters.py

     
    725725
    726726def filesizeformat(bytes):
    727727    """
    728     Formats the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB,
     728    Formats the value like a 'human-readable' file size (i.e. 13 KiB, 4.1 MiB,
    729729    102 bytes, etc).
    730730    """
    731731    try:
     
    733733    except TypeError:
    734734        return u"0 bytes"
    735735
    736     if bytes < 1024:
     736    if bytes < 1024 ** 1:
    737737        return ungettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': bytes}
    738     if bytes < 1024 * 1024:
    739         return ugettext("%.1f KB") % (bytes / 1024)
    740     if bytes < 1024 * 1024 * 1024:
    741         return ugettext("%.1f MB") % (bytes / (1024 * 1024))
    742     return ugettext("%.1f GB") % (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))
    743743filesizeformat.is_safe = True
    744744
    745745def pluralize(value, arg=u's'):
Back to Top