Support CSS class definition directly in CHOICES iterable

This commit is contained in:
jeremystretch
2021-12-16 10:03:23 -05:00
parent 419f86a4a5
commit 0d3b50a5e5
19 changed files with 110 additions and 214 deletions

View File

@@ -16,19 +16,10 @@ class VirtualMachineStatusChoices(ChoiceSet):
STATUS_DECOMMISSIONING = 'decommissioning'
CHOICES = [
(STATUS_OFFLINE, 'Offline'),
(STATUS_ACTIVE, 'Active'),
(STATUS_PLANNED, 'Planned'),
(STATUS_STAGED, 'Staged'),
(STATUS_FAILED, 'Failed'),
(STATUS_DECOMMISSIONING, 'Decommissioning'),
(STATUS_OFFLINE, 'Offline', 'warning'),
(STATUS_ACTIVE, 'Active', 'success'),
(STATUS_PLANNED, 'Planned', 'info'),
(STATUS_STAGED, 'Staged', 'primary'),
(STATUS_FAILED, 'Failed', 'danger'),
(STATUS_DECOMMISSIONING, 'Decommissioning', 'warning'),
]
CSS_CLASSES = {
STATUS_OFFLINE: 'warning',
STATUS_ACTIVE: 'success',
STATUS_PLANNED: 'info',
STATUS_STAGED: 'primary',
STATUS_FAILED: 'danger',
STATUS_DECOMMISSIONING: 'warning',
}

View File

@@ -329,7 +329,7 @@ class VirtualMachine(PrimaryModel, ConfigContextModel):
})
def get_status_class(self):
return VirtualMachineStatusChoices.CSS_CLASSES.get(self.status)
return VirtualMachineStatusChoices.colors.get(self.status, 'secondary')
@property
def primary_ip(self):