mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-21 21:02:23 -06:00
Relocate CSS classes for ChoiceFields from model to ChoiceSet
This commit is contained in:
@@ -21,6 +21,14 @@ class SiteStatusChoices(ChoiceSet):
|
||||
(STATUS_RETIRED, 'Retired'),
|
||||
)
|
||||
|
||||
CSS_CLASSES = {
|
||||
STATUS_PLANNED: 'info',
|
||||
STATUS_STAGING: 'primary',
|
||||
STATUS_ACTIVE: 'success',
|
||||
STATUS_DECOMMISSIONING: 'warning',
|
||||
STATUS_RETIRED: 'danger',
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# Racks
|
||||
@@ -74,6 +82,14 @@ class RackStatusChoices(ChoiceSet):
|
||||
(STATUS_DEPRECATED, 'Deprecated'),
|
||||
)
|
||||
|
||||
CSS_CLASSES = {
|
||||
STATUS_RESERVED: 'warning',
|
||||
STATUS_AVAILABLE: 'success',
|
||||
STATUS_PLANNED: 'info',
|
||||
STATUS_ACTIVE: 'primary',
|
||||
STATUS_DEPRECATED: 'danger',
|
||||
}
|
||||
|
||||
|
||||
class RackDimensionUnitChoices(ChoiceSet):
|
||||
|
||||
@@ -147,6 +163,16 @@ class DeviceStatusChoices(ChoiceSet):
|
||||
(STATUS_DECOMMISSIONING, 'Decommissioning'),
|
||||
)
|
||||
|
||||
CSS_CLASSES = {
|
||||
STATUS_OFFLINE: 'warning',
|
||||
STATUS_ACTIVE: 'success',
|
||||
STATUS_PLANNED: 'info',
|
||||
STATUS_STAGED: 'primary',
|
||||
STATUS_FAILED: 'danger',
|
||||
STATUS_INVENTORY: 'default',
|
||||
STATUS_DECOMMISSIONING: 'warning',
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# ConsolePorts
|
||||
@@ -933,6 +959,12 @@ class CableStatusChoices(ChoiceSet):
|
||||
(STATUS_DECOMMISSIONING, 'Decommissioning'),
|
||||
)
|
||||
|
||||
CSS_CLASSES = {
|
||||
STATUS_CONNECTED: 'success',
|
||||
STATUS_PLANNED: 'info',
|
||||
STATUS_DECOMMISSIONING: 'warning',
|
||||
}
|
||||
|
||||
|
||||
class CableLengthUnitChoices(ChoiceSet):
|
||||
|
||||
@@ -967,6 +999,13 @@ class PowerFeedStatusChoices(ChoiceSet):
|
||||
(STATUS_FAILED, 'Failed'),
|
||||
)
|
||||
|
||||
CSS_CLASSES = {
|
||||
STATUS_OFFLINE: 'warning',
|
||||
STATUS_ACTIVE: 'success',
|
||||
STATUS_PLANNED: 'info',
|
||||
STATUS_FAILED: 'danger',
|
||||
}
|
||||
|
||||
|
||||
class PowerFeedTypeChoices(ChoiceSet):
|
||||
|
||||
@@ -978,6 +1017,11 @@ class PowerFeedTypeChoices(ChoiceSet):
|
||||
(TYPE_REDUNDANT, 'Redundant'),
|
||||
)
|
||||
|
||||
CSS_CLASSES = {
|
||||
TYPE_PRIMARY: 'success',
|
||||
TYPE_REDUNDANT: 'info',
|
||||
}
|
||||
|
||||
|
||||
class PowerFeedSupplyChoices(ChoiceSet):
|
||||
|
||||
|
||||
@@ -600,16 +600,6 @@ class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
|
||||
'device_type', 'device_role', 'tenant', 'platform', 'site', 'rack', 'status', 'cluster',
|
||||
]
|
||||
|
||||
STATUS_CLASS_MAP = {
|
||||
DeviceStatusChoices.STATUS_OFFLINE: 'warning',
|
||||
DeviceStatusChoices.STATUS_ACTIVE: 'success',
|
||||
DeviceStatusChoices.STATUS_PLANNED: 'info',
|
||||
DeviceStatusChoices.STATUS_STAGED: 'primary',
|
||||
DeviceStatusChoices.STATUS_FAILED: 'danger',
|
||||
DeviceStatusChoices.STATUS_INVENTORY: 'default',
|
||||
DeviceStatusChoices.STATUS_DECOMMISSIONING: 'warning',
|
||||
}
|
||||
|
||||
class Meta:
|
||||
ordering = ('_name', 'pk') # Name may be null
|
||||
unique_together = (
|
||||
@@ -881,7 +871,7 @@ class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
|
||||
return Device.objects.filter(parent_bay__device=self.pk)
|
||||
|
||||
def get_status_class(self):
|
||||
return self.STATUS_CLASS_MAP.get(self.status)
|
||||
return DeviceStatusChoices.CSS_CLASSES.get(self.status)
|
||||
|
||||
|
||||
#
|
||||
@@ -973,12 +963,6 @@ class Cable(ChangeLoggedModel, CustomFieldModel):
|
||||
'color', 'length', 'length_unit',
|
||||
]
|
||||
|
||||
STATUS_CLASS_MAP = {
|
||||
CableStatusChoices.STATUS_CONNECTED: 'success',
|
||||
CableStatusChoices.STATUS_PLANNED: 'info',
|
||||
CableStatusChoices.STATUS_DECOMMISSIONING: 'warning',
|
||||
}
|
||||
|
||||
class Meta:
|
||||
ordering = ['pk']
|
||||
unique_together = (
|
||||
@@ -1159,7 +1143,7 @@ class Cable(ChangeLoggedModel, CustomFieldModel):
|
||||
)
|
||||
|
||||
def get_status_class(self):
|
||||
return self.STATUS_CLASS_MAP.get(self.status)
|
||||
return CableStatusChoices.CSS_CLASSES.get(self.status)
|
||||
|
||||
def get_compatible_types(self):
|
||||
"""
|
||||
|
||||
@@ -156,18 +156,6 @@ class PowerFeed(ChangeLoggedModel, CableTermination, CustomFieldModel):
|
||||
'available_power',
|
||||
]
|
||||
|
||||
STATUS_CLASS_MAP = {
|
||||
PowerFeedStatusChoices.STATUS_OFFLINE: 'warning',
|
||||
PowerFeedStatusChoices.STATUS_ACTIVE: 'success',
|
||||
PowerFeedStatusChoices.STATUS_PLANNED: 'info',
|
||||
PowerFeedStatusChoices.STATUS_FAILED: 'danger',
|
||||
}
|
||||
|
||||
TYPE_CLASS_MAP = {
|
||||
PowerFeedTypeChoices.TYPE_PRIMARY: 'success',
|
||||
PowerFeedTypeChoices.TYPE_REDUNDANT: 'info',
|
||||
}
|
||||
|
||||
class Meta:
|
||||
ordering = ['power_panel', 'name']
|
||||
unique_together = ['power_panel', 'name']
|
||||
@@ -225,7 +213,7 @@ class PowerFeed(ChangeLoggedModel, CableTermination, CustomFieldModel):
|
||||
return self.power_panel
|
||||
|
||||
def get_type_class(self):
|
||||
return self.TYPE_CLASS_MAP.get(self.type)
|
||||
return PowerFeedTypeChoices.CSS_CLASSES.get(self.type)
|
||||
|
||||
def get_status_class(self):
|
||||
return self.STATUS_CLASS_MAP.get(self.status)
|
||||
return PowerFeedStatusChoices.CSS_CLASSES.get(self.status)
|
||||
|
||||
@@ -276,14 +276,6 @@ class Rack(ChangeLoggedModel, CustomFieldModel):
|
||||
'outer_depth', 'outer_unit',
|
||||
]
|
||||
|
||||
STATUS_CLASS_MAP = {
|
||||
RackStatusChoices.STATUS_RESERVED: 'warning',
|
||||
RackStatusChoices.STATUS_AVAILABLE: 'success',
|
||||
RackStatusChoices.STATUS_PLANNED: 'info',
|
||||
RackStatusChoices.STATUS_ACTIVE: 'primary',
|
||||
RackStatusChoices.STATUS_DEPRECATED: 'danger',
|
||||
}
|
||||
|
||||
class Meta:
|
||||
ordering = ('site', 'group', '_name', 'pk') # (site, group, name) may be non-unique
|
||||
unique_together = (
|
||||
@@ -379,7 +371,7 @@ class Rack(ChangeLoggedModel, CustomFieldModel):
|
||||
return self.name
|
||||
|
||||
def get_status_class(self):
|
||||
return self.STATUS_CLASS_MAP.get(self.status)
|
||||
return RackStatusChoices.CSS_CLASSES.get(self.status)
|
||||
|
||||
def get_rack_units(self, user=None, face=DeviceFaceChoices.FACE_FRONT, exclude=None, expand_devices=True):
|
||||
"""
|
||||
|
||||
@@ -199,14 +199,6 @@ class Site(ChangeLoggedModel, CustomFieldModel):
|
||||
'shipping_address', 'latitude', 'longitude', 'contact_name', 'contact_phone', 'contact_email',
|
||||
]
|
||||
|
||||
STATUS_CLASS_MAP = {
|
||||
SiteStatusChoices.STATUS_PLANNED: 'info',
|
||||
SiteStatusChoices.STATUS_STAGING: 'primary',
|
||||
SiteStatusChoices.STATUS_ACTIVE: 'success',
|
||||
SiteStatusChoices.STATUS_DECOMMISSIONING: 'warning',
|
||||
SiteStatusChoices.STATUS_RETIRED: 'danger',
|
||||
}
|
||||
|
||||
class Meta:
|
||||
ordering = ('_name',)
|
||||
|
||||
@@ -238,4 +230,4 @@ class Site(ChangeLoggedModel, CustomFieldModel):
|
||||
)
|
||||
|
||||
def get_status_class(self):
|
||||
return self.STATUS_CLASS_MAP.get(self.status)
|
||||
return SiteStatusChoices.CSS_CLASSES.get(self.status)
|
||||
|
||||
Reference in New Issue
Block a user