mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #6667: Display VM memory as GB/TB as appropriate
This commit is contained in:
@@ -138,7 +138,7 @@
|
||||
<td><i class="mdi mdi-chip"></i> Memory</td>
|
||||
<td>
|
||||
{% if object.memory %}
|
||||
{{ object.memory }} MB
|
||||
<span title="{{ object.memory }} MB">{{ object.memory|humanize_megabytes }}</span>
|
||||
{% else %}
|
||||
<span class="text-muted">—</span>
|
||||
{% endif %}
|
||||
|
||||
@@ -129,6 +129,20 @@ def humanize_speed(speed):
|
||||
return '{} Kbps'.format(speed)
|
||||
|
||||
|
||||
@register.filter()
|
||||
def humanize_megabytes(mb):
|
||||
"""
|
||||
Express a number of megabytes in the most suitable unit (e.g. gigabytes or terabytes).
|
||||
"""
|
||||
if not mb:
|
||||
return ''
|
||||
if mb >= 1048576:
|
||||
return f'{int(mb / 1048576)} TB'
|
||||
if mb >= 1024:
|
||||
return f'{int(mb / 1024)} GB'
|
||||
return f'{mb} MB'
|
||||
|
||||
|
||||
@register.filter()
|
||||
def tzoffset(value):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user