Update VirtualMachineType default memory labels and display rendering to use the configured RAM base unit, matching the existing VirtualMachine and VirtualDisk behavior. Render default memory with the existing humanized RAM capacity helper and keep the model field metadata unit-agnostic. --------- Co-authored-by: Martin Hauser <mhauser@netboxlabs.com>
This commit is contained in:
parent
e727da5cad
commit
c56090f994
|
|
@ -0,0 +1,2 @@
|
|||
{% load helpers %}
|
||||
{{ value|humanize_ram_capacity }}
|
||||
|
|
@ -91,7 +91,7 @@ class VirtualMachineTypeBulkEditForm(PrimaryModelBulkEditForm):
|
|||
required=False,
|
||||
)
|
||||
default_memory = forms.IntegerField(
|
||||
label=_('Default Memory (MB)'),
|
||||
label=_('Default memory'),
|
||||
required=False,
|
||||
)
|
||||
|
||||
|
|
@ -104,6 +104,14 @@ class VirtualMachineTypeBulkEditForm(PrimaryModelBulkEditForm):
|
|||
'default_platform', 'default_vcpus', 'default_memory', 'description', 'comments',
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Set unit label based on configured RAM_BASE_UNIT (MB vs MiB)
|
||||
self.fields['default_memory'].label = _('Default memory ({unit})').format(
|
||||
unit=get_capacity_unit_label(settings.RAM_BASE_UNIT)
|
||||
)
|
||||
|
||||
|
||||
class VirtualMachineBulkEditForm(PrimaryModelBulkEditForm):
|
||||
virtual_machine_type = DynamicModelChoiceField(
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ class VirtualMachineTypeFilterForm(PrimaryModelFilterSetForm):
|
|||
required=False,
|
||||
)
|
||||
default_memory = forms.IntegerField(
|
||||
label=_('Default memory (MB)'),
|
||||
label=_('Default memory'),
|
||||
required=False,
|
||||
min_value=0,
|
||||
)
|
||||
|
|
@ -140,6 +140,14 @@ class VirtualMachineTypeFilterForm(PrimaryModelFilterSetForm):
|
|||
|
||||
tag = TagFilterField(model)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Set unit label based on configured RAM_BASE_UNIT (MB vs MiB)
|
||||
self.fields['default_memory'].label = _('Default memory ({unit})').format(
|
||||
unit=get_capacity_unit_label(settings.RAM_BASE_UNIT)
|
||||
)
|
||||
|
||||
|
||||
class VirtualMachineFilterForm(
|
||||
LocalConfigContextFilterForm,
|
||||
|
|
|
|||
|
|
@ -192,6 +192,14 @@ class VirtualMachineTypeForm(PrimaryModelForm):
|
|||
'owner', 'comments', 'tags',
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Set unit label based on configured RAM_BASE_UNIT (MB vs MiB)
|
||||
self.fields['default_memory'].label = _('Default memory ({unit})').format(
|
||||
unit=get_capacity_unit_label(settings.RAM_BASE_UNIT)
|
||||
)
|
||||
|
||||
|
||||
class VirtualMachineForm(TenancyForm, PrimaryModelForm):
|
||||
virtual_machine_type = forms.ModelChoiceField(
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class VirtualMachineType(ImageAttachmentsMixin, PrimaryModel):
|
|||
validators=(MinValueValidator(decimal.Decimal('0.01')),),
|
||||
)
|
||||
default_memory = models.PositiveIntegerField(
|
||||
verbose_name=_('default memory (MB)'),
|
||||
verbose_name=_('default memory'),
|
||||
blank=True,
|
||||
null=True,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -49,6 +49,10 @@ class VirtualMachineTypeTable(PrimaryModelTable):
|
|||
'pk', 'name', 'default_platform', 'default_vcpus', 'default_memory', 'virtual_machine_count', 'description',
|
||||
)
|
||||
|
||||
def render_default_memory(self, value):
|
||||
return humanize_ram_capacity(value)
|
||||
|
||||
|
||||
#
|
||||
# Virtual machines
|
||||
#
|
||||
|
|
|
|||
|
|
@ -26,7 +26,11 @@ class VirtualMachineTypePanel(panels.ObjectAttributesPanel):
|
|||
name = attrs.TextAttr('name')
|
||||
default_platform = attrs.RelatedObjectAttr('default_platform', linkify=True)
|
||||
default_vcpus = attrs.TextAttr('default_vcpus', label=_('Default vCPUs'))
|
||||
default_memory = attrs.TextAttr('default_memory', format_string=_('{0} MB'), label=_('Default memory'))
|
||||
default_memory = attrs.TemplatedAttr(
|
||||
'default_memory',
|
||||
template_name='virtualization/virtualmachinetype/attrs/default_memory.html',
|
||||
label=_('Default memory')
|
||||
)
|
||||
description = attrs.TextAttr('description')
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue