utils.crhumanize — Utilities for humanizing data¶
-
human_readable_filesize
(size_in_bytes)¶ Humanize the given file size in bytes.
Returns a number suffixed with
B
,KB
,MB
,GB
orTB
.Examples
>>> from django_cradmin.utils import crhumanize >>> crhumanize.human_readable_filesize(1) '1B' >>> crhumanize.human_readable_filesize(2344234345) '2.34GB' >>> crhumanize.human_readable_filesize(23442343451234) '23.44TB'
-
dehumanize_readable_filesize
(humanized_size)¶ Does the opposite of
human_readable_filesize()
.Takes a string containing a number suffixed with
B
,KB
,MB
,GB
orTB
, and returns an int with the number of bytes.Examples
>>> from django_cradmin.utils import crhumanize >>> crhumanize.dehumanize_readable_filesize('999B') 999 >>> crhumanize.dehumanize_readable_filesize('2.34GB') 2340000000 >>> crhumanize.dehumanize_readable_filesize('43.312TB') 43312000000000