Ticket #18645: defaultfilters.diff

File defaultfilters.diff, 1.6 KB (added by jerome.renard@…, 12 years ago)

patch for filesizeformat

  • django/template/defaultfilters.py

    diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
    index d2c5b03..331bccb 100644
    a b def filesizeformat(bytes):  
    827827
    828828    filesize_number_format = lambda value: formats.number_format(round(value, 1), 1)
    829829
    830     if bytes < 1024:
     830    Kb = 1<<10
     831    Mb = 1<<20
     832    Gb = 1<<30
     833    Tb = 1<<40
     834    Pb = 1<<50
     835
     836    if bytes < Kb:
    831837        return ungettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': bytes}
    832     if bytes < 1024 * 1024:
    833         return ugettext("%s KB") % filesize_number_format(bytes / 1024)
    834     if bytes < 1024 * 1024 * 1024:
    835         return ugettext("%s MB") % filesize_number_format(bytes / (1024 * 1024))
    836     if bytes < 1024 * 1024 * 1024 * 1024:
    837         return ugettext("%s GB") % filesize_number_format(bytes / (1024 * 1024 * 1024))
    838     if bytes < 1024 * 1024 * 1024 * 1024 * 1024:
    839         return ugettext("%s TB") % filesize_number_format(bytes / (1024 * 1024 * 1024 * 1024))
    840     return ugettext("%s PB") % filesize_number_format(bytes / (1024 * 1024 * 1024 * 1024 * 1024))
     838    if bytes < Mb:
     839        return ugettext("%s KB") % filesize_number_format(bytes / Kb)
     840    if bytes < Gb:
     841        return ugettext("%s MB") % filesize_number_format(bytes / Mb)
     842    if bytes < Tb:
     843        return ugettext("%s GB") % filesize_number_format(bytes / Gb)
     844    if bytes < Pb:
     845        return ugettext("%s TB") % filesize_number_format(bytes / Tb)
     846    return ugettext("%s PB") % filesize_number_format(bytes / Pb)
    841847
    842848@register.filter(is_safe=False)
    843849def pluralize(value, arg='s'):
Back to Top