Merge "Fix inappropriate display for inf value of RAM and Storage."
This commit is contained in:
commit
6a52b59c29
@ -47,7 +47,7 @@
|
||||
<div class="d3_quota_bar">
|
||||
<div class="d3_pie_chart" data-used="{% widthratio usage.limits.totalGigabytesUsed usage.limits.maxTotalVolumeGigabytes 100 %}"></div>
|
||||
<strong>{% trans "Volume Storage" %} <br />
|
||||
{% blocktrans with used=usage.limits.totalGigabytesUsed|diskgbformat available=usage.limits.maxTotalVolumeGigabytes|diskgbformat %}Used <span> {{ used }} </span> of <span> {{ available }} </span>{% endblocktrans %}
|
||||
{% blocktrans with used=usage.limits.totalGigabytesUsed|diskgbformat available=usage.limits.maxTotalVolumeGigabytes|quotainf|diskgbformat %}Used <span> {{ used }} </span> of <span> {{ available }} </span>{% endblocktrans %}
|
||||
</strong>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
@ -64,26 +64,25 @@ def filesizeformat(bytes, filesize_number_format):
|
||||
filesize_number_format(bytes / (1024 * 1024 * 1024 * 1024 * 1024))
|
||||
|
||||
|
||||
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')
|
||||
def mbformat(mb):
|
||||
if not mb:
|
||||
return 0
|
||||
return filesizeformat(mb * 1024 * 1024, int_format).replace(' ', '')
|
||||
return float_cast_filesizeformat(mb, 1024 * 1024, int_format)
|
||||
|
||||
|
||||
@register.filter(name='mb_float_format')
|
||||
def mb_float_format(mb):
|
||||
"""Takes a size value in mb, and prints returns the data in a
|
||||
saner unit.
|
||||
"""
|
||||
if not mb:
|
||||
return 0
|
||||
return filesizeformat(mb * 1024 * 1024, float_format)
|
||||
return float_cast_filesizeformat(mb, 1024 * 1024, float_format)
|
||||
|
||||
|
||||
@register.filter(name='diskgbformat')
|
||||
def diskgbformat(gb):
|
||||
if not gb:
|
||||
gb = 0
|
||||
return filesizeformat(gb * 1024 * 1024 * 1024,
|
||||
float_format).replace(' ', '')
|
||||
return float_cast_filesizeformat(gb, 1024 * 1024 * 1024, float_format)
|
||||
|
@ -57,7 +57,20 @@ class TemplateTagTests(test.TestCase):
|
||||
size_str = ('5|diskgbformat', '10|diskgbformat',
|
||||
'5555|mb_float_format', '80|mb_float_format',
|
||||
'.5|mbformat', '0.005|mbformat', '0.0005|mbformat')
|
||||
expected = u' 5.0GB 10.0GB 5.4 GB 80.0 MB 512KB 5KB 524Bytes '
|
||||
expected = u' 5.0GB 10.0GB 5.4GB 80.0MB 512KB 5KB 524Bytes '
|
||||
|
||||
text = ''
|
||||
for size_filter in size_str:
|
||||
text += '{{' + size_filter + '}} '
|
||||
|
||||
rendered_str = self.render_template(tag_require='sizeformat',
|
||||
template_text=text)
|
||||
self.assertEqual(rendered_str, expected)
|
||||
|
||||
def test_size_format_filters_with_string(self):
|
||||
size_str = ('"test"|diskgbformat', '"limit"|mb_float_format',
|
||||
'"no limit"|mbformat')
|
||||
expected = u' test limit no limit '
|
||||
|
||||
text = ''
|
||||
for size_filter in size_str:
|
||||
|
Loading…
x
Reference in New Issue
Block a user