**** CubicPower OpenStack Study ****
def int_format(value):
return int(value)
**** CubicPower OpenStack Study ****
def float_format(value):
return formats.number_format(round(value, 1), 1)
**** CubicPower OpenStack Study ****
def filesizeformat(bytes, filesize_number_format):
try:
bytes = float(bytes)
except (TypeError, ValueError, UnicodeDecodeError):
return translation.ungettext_lazy("%(size)d Byte",
"%(size)d Bytes", 0) % {'size': 0}
if bytes < 1024:
bytes = int(bytes)
return translation.ungettext_lazy("%(size)d Byte",
"%(size)d Bytes", bytes) % {'size': bytes}
if bytes < 1024 * 1024:
return translation.ugettext_lazy("%s KB") % \
filesize_number_format(bytes / 1024)
if bytes < 1024 * 1024 * 1024:
return translation.ugettext_lazy("%s MB") % \
filesize_number_format(bytes / (1024 * 1024))
if bytes < 1024 * 1024 * 1024 * 1024:
return translation.ugettext_lazy("%s GB") % \
filesize_number_format(bytes / (1024 * 1024 * 1024))
if bytes < 1024 * 1024 * 1024 * 1024 * 1024:
return translation.ugettext_lazy("%s TB") % \
filesize_number_format(bytes / (1024 * 1024 * 1024 * 1024))
return translation.ugettext_lazy("%s PB") % \
filesize_number_format(bytes / (1024 * 1024 * 1024 * 1024 * 1024))
**** CubicPower OpenStack Study ****
def float_cast_filesizeformat(value, multiplier=1, format=int_format):
try:
value = float(value)
value = filesizeformat(value * multiplier, format).replace(' ', '')
except (TypeError, ValueError):
value = value or '0 bytes'
return value
@register.filter(name='mbformat')
**** CubicPower OpenStack Study ****
def mbformat(mb):
return float_cast_filesizeformat(mb, 1024 * 1024, int_format)
@register.filter(name='mb_float_format')
**** CubicPower OpenStack Study ****
def mb_float_format(mb):
return float_cast_filesizeformat(mb, 1024 * 1024, float_format)
@register.filter(name='diskgbformat')
**** CubicPower OpenStack Study ****
def diskgbformat(gb):
return float_cast_filesizeformat(gb, 1024 * 1024 * 1024, float_format)