Should we move filesizeformat to django.contrib.humanize?

205 views
Skip to first unread message

João Sampaio

unread,
Oct 29, 2016, 10:01:19 AM10/29/16
to django-d...@googlegroups.com
Hi.

    Currently, if we want to convent a filesize from bytes to a human-readable size, we have to do:

    from django.template.defaultfilters import filesizeformat
    print(filesizeformat(size_in_bytes))

    How about we move that filter into django.contrib.humanize? Maybe the filter would be a shortcut to the django.contrib.humanize.filesizeformat function? Or vice-versa.

    Use case: I am downloading a file in a custom manage.py command, and I want to print it's size to the terminal (through parsing the Content-Length header, which comes in bytes).

Thanks!

Tim Graham

unread,
Oct 29, 2016, 4:49:15 PM10/29/16
to Django developers (Contributions to Django itself)
Adding a helper function that does the formatting make sense in the spirit of #27106. Putting that helper in humanize makes logical sense, however, it would be slightly unclean to have a built-in template tag depend on a contrib app and I'm not sure that deprecating in the built-in filter in favor of an equivalent version in humanize would be worth the disruption. Therefore, the helper function might be best in django.utils.

https://code.djangoproject.com/ticket/27106
Reply all
Reply to author
Forward
0 new messages