mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Relocate CSS classes for ChoiceFields from model to ChoiceSet
This commit is contained in:
@@ -30,6 +30,13 @@ class PrefixStatusChoices(ChoiceSet):
|
||||
(STATUS_DEPRECATED, 'Deprecated'),
|
||||
)
|
||||
|
||||
CSS_CLASSES = {
|
||||
STATUS_CONTAINER: 'default',
|
||||
STATUS_ACTIVE: 'primary',
|
||||
STATUS_RESERVED: 'info',
|
||||
STATUS_DEPRECATED: 'danger',
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# IPAddresses
|
||||
@@ -51,6 +58,14 @@ class IPAddressStatusChoices(ChoiceSet):
|
||||
(STATUS_SLAAC, 'SLAAC'),
|
||||
)
|
||||
|
||||
CSS_CLASSES = {
|
||||
STATUS_ACTIVE: 'primary',
|
||||
STATUS_RESERVED: 'info',
|
||||
STATUS_DEPRECATED: 'danger',
|
||||
STATUS_DHCP: 'success',
|
||||
STATUS_SLAAC: 'success',
|
||||
}
|
||||
|
||||
|
||||
class IPAddressRoleChoices(ChoiceSet):
|
||||
|
||||
@@ -74,6 +89,17 @@ class IPAddressRoleChoices(ChoiceSet):
|
||||
(ROLE_CARP, 'CARP'),
|
||||
)
|
||||
|
||||
CSS_CLASSES = {
|
||||
ROLE_LOOPBACK: 'default',
|
||||
ROLE_SECONDARY: 'primary',
|
||||
ROLE_ANYCAST: 'warning',
|
||||
ROLE_VIP: 'success',
|
||||
ROLE_VRRP: 'success',
|
||||
ROLE_HSRP: 'success',
|
||||
ROLE_GLBP: 'success',
|
||||
ROLE_CARP: 'success',
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# VLANs
|
||||
@@ -91,6 +117,12 @@ class VLANStatusChoices(ChoiceSet):
|
||||
(STATUS_DEPRECATED, 'Deprecated'),
|
||||
)
|
||||
|
||||
CSS_CLASSES = {
|
||||
STATUS_ACTIVE: 'primary',
|
||||
STATUS_RESERVED: 'info',
|
||||
STATUS_DEPRECATED: 'danger',
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# Services
|
||||
|
||||
@@ -420,13 +420,6 @@ class Prefix(ChangeLoggedModel, CustomFieldModel):
|
||||
'site', 'vrf', 'tenant', 'vlan', 'status', 'role', 'is_pool', 'description',
|
||||
]
|
||||
|
||||
STATUS_CLASS_MAP = {
|
||||
'container': 'default',
|
||||
'active': 'primary',
|
||||
'reserved': 'info',
|
||||
'deprecated': 'danger',
|
||||
}
|
||||
|
||||
class Meta:
|
||||
ordering = (F('vrf').asc(nulls_first=True), 'prefix', 'pk') # (vrf, prefix) may be non-unique
|
||||
verbose_name_plural = 'prefixes'
|
||||
@@ -507,7 +500,7 @@ class Prefix(ChangeLoggedModel, CustomFieldModel):
|
||||
prefix_length = property(fset=_set_prefix_length)
|
||||
|
||||
def get_status_class(self):
|
||||
return self.STATUS_CLASS_MAP.get(self.status)
|
||||
return PrefixStatusChoices.CSS_CLASSES.get(self.status)
|
||||
|
||||
def get_duplicates(self):
|
||||
return Prefix.objects.filter(vrf=self.vrf, prefix=str(self.prefix)).exclude(pk=self.pk)
|
||||
@@ -699,25 +692,6 @@ class IPAddress(ChangeLoggedModel, CustomFieldModel):
|
||||
'vrf', 'tenant', 'status', 'role', 'description',
|
||||
]
|
||||
|
||||
STATUS_CLASS_MAP = {
|
||||
'active': 'primary',
|
||||
'reserved': 'info',
|
||||
'deprecated': 'danger',
|
||||
'dhcp': 'success',
|
||||
'slaac': 'success',
|
||||
}
|
||||
|
||||
ROLE_CLASS_MAP = {
|
||||
'loopback': 'default',
|
||||
'secondary': 'primary',
|
||||
'anycast': 'warning',
|
||||
'vip': 'success',
|
||||
'vrrp': 'success',
|
||||
'hsrp': 'success',
|
||||
'glbp': 'success',
|
||||
'carp': 'success',
|
||||
}
|
||||
|
||||
class Meta:
|
||||
ordering = ('address', 'pk') # address may be non-unique
|
||||
verbose_name = 'IP address'
|
||||
@@ -840,10 +814,10 @@ class IPAddress(ChangeLoggedModel, CustomFieldModel):
|
||||
mask_length = property(fset=_set_mask_length)
|
||||
|
||||
def get_status_class(self):
|
||||
return self.STATUS_CLASS_MAP.get(self.status)
|
||||
return IPAddressStatusChoices.CSS_CLASSES.get(self.status)
|
||||
|
||||
def get_role_class(self):
|
||||
return self.ROLE_CLASS_MAP[self.role]
|
||||
return IPAddressRoleChoices.CSS_CLASSES.get(self.role)
|
||||
|
||||
|
||||
class VLANGroup(ChangeLoggedModel):
|
||||
@@ -967,12 +941,6 @@ class VLAN(ChangeLoggedModel, CustomFieldModel):
|
||||
'site', 'group', 'tenant', 'status', 'role', 'description',
|
||||
]
|
||||
|
||||
STATUS_CLASS_MAP = {
|
||||
'active': 'primary',
|
||||
'reserved': 'info',
|
||||
'deprecated': 'danger',
|
||||
}
|
||||
|
||||
class Meta:
|
||||
ordering = ('site', 'group', 'vid', 'pk') # (site, group, vid) may be non-unique
|
||||
unique_together = [
|
||||
@@ -1013,7 +981,7 @@ class VLAN(ChangeLoggedModel, CustomFieldModel):
|
||||
return f'{self.name} ({self.vid})'
|
||||
|
||||
def get_status_class(self):
|
||||
return self.STATUS_CLASS_MAP[self.status]
|
||||
return VLANStatusChoices.CSS_CLASSES.get(self.status)
|
||||
|
||||
def get_interfaces(self):
|
||||
# Return all device interfaces assigned to this VLAN
|
||||
|
||||
Reference in New Issue
Block a user