Relocate CSS classes for ChoiceFields from model to ChoiceSet

This commit is contained in:
Jeremy Stretch 2020-09-24 16:35:53 -04:00
parent bddd010310
commit 1b55285167
13 changed files with 114 additions and 114 deletions

View File

@ -23,6 +23,15 @@ class CircuitStatusChoices(ChoiceSet):
(STATUS_DECOMMISSIONED, 'Decommissioned'), (STATUS_DECOMMISSIONED, 'Decommissioned'),
) )
CSS_CLASSES = {
STATUS_DEPROVISIONING: 'warning',
STATUS_ACTIVE: 'success',
STATUS_PLANNED: 'info',
STATUS_PROVISIONING: 'primary',
STATUS_OFFLINE: 'danger',
STATUS_DECOMMISSIONED: 'default',
}
# #
# CircuitTerminations # CircuitTerminations

View File

@ -191,15 +191,6 @@ class Circuit(ChangeLoggedModel, CustomFieldModel):
'provider', 'type', 'status', 'tenant', 'install_date', 'commit_rate', 'description', 'provider', 'type', 'status', 'tenant', 'install_date', 'commit_rate', 'description',
] ]
STATUS_CLASS_MAP = {
CircuitStatusChoices.STATUS_DEPROVISIONING: 'warning',
CircuitStatusChoices.STATUS_ACTIVE: 'success',
CircuitStatusChoices.STATUS_PLANNED: 'info',
CircuitStatusChoices.STATUS_PROVISIONING: 'primary',
CircuitStatusChoices.STATUS_OFFLINE: 'danger',
CircuitStatusChoices.STATUS_DECOMMISSIONED: 'default',
}
class Meta: class Meta:
ordering = ['provider', 'cid'] ordering = ['provider', 'cid']
unique_together = ['provider', 'cid'] unique_together = ['provider', 'cid']
@ -224,7 +215,7 @@ class Circuit(ChangeLoggedModel, CustomFieldModel):
) )
def get_status_class(self): def get_status_class(self):
return self.STATUS_CLASS_MAP.get(self.status) return CircuitStatusChoices.CSS_CLASSES.get(self.status)
def _get_termination(self, side): def _get_termination(self, side):
for ct in self.terminations.all(): for ct in self.terminations.all():

View File

@ -21,6 +21,14 @@ class SiteStatusChoices(ChoiceSet):
(STATUS_RETIRED, 'Retired'), (STATUS_RETIRED, 'Retired'),
) )
CSS_CLASSES = {
STATUS_PLANNED: 'info',
STATUS_STAGING: 'primary',
STATUS_ACTIVE: 'success',
STATUS_DECOMMISSIONING: 'warning',
STATUS_RETIRED: 'danger',
}
# #
# Racks # Racks
@ -74,6 +82,14 @@ class RackStatusChoices(ChoiceSet):
(STATUS_DEPRECATED, 'Deprecated'), (STATUS_DEPRECATED, 'Deprecated'),
) )
CSS_CLASSES = {
STATUS_RESERVED: 'warning',
STATUS_AVAILABLE: 'success',
STATUS_PLANNED: 'info',
STATUS_ACTIVE: 'primary',
STATUS_DEPRECATED: 'danger',
}
class RackDimensionUnitChoices(ChoiceSet): class RackDimensionUnitChoices(ChoiceSet):
@ -147,6 +163,16 @@ class DeviceStatusChoices(ChoiceSet):
(STATUS_DECOMMISSIONING, 'Decommissioning'), (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 # ConsolePorts
@ -933,6 +959,12 @@ class CableStatusChoices(ChoiceSet):
(STATUS_DECOMMISSIONING, 'Decommissioning'), (STATUS_DECOMMISSIONING, 'Decommissioning'),
) )
CSS_CLASSES = {
STATUS_CONNECTED: 'success',
STATUS_PLANNED: 'info',
STATUS_DECOMMISSIONING: 'warning',
}
class CableLengthUnitChoices(ChoiceSet): class CableLengthUnitChoices(ChoiceSet):
@ -967,6 +999,13 @@ class PowerFeedStatusChoices(ChoiceSet):
(STATUS_FAILED, 'Failed'), (STATUS_FAILED, 'Failed'),
) )
CSS_CLASSES = {
STATUS_OFFLINE: 'warning',
STATUS_ACTIVE: 'success',
STATUS_PLANNED: 'info',
STATUS_FAILED: 'danger',
}
class PowerFeedTypeChoices(ChoiceSet): class PowerFeedTypeChoices(ChoiceSet):
@ -978,6 +1017,11 @@ class PowerFeedTypeChoices(ChoiceSet):
(TYPE_REDUNDANT, 'Redundant'), (TYPE_REDUNDANT, 'Redundant'),
) )
CSS_CLASSES = {
TYPE_PRIMARY: 'success',
TYPE_REDUNDANT: 'info',
}
class PowerFeedSupplyChoices(ChoiceSet): class PowerFeedSupplyChoices(ChoiceSet):

View File

@ -600,16 +600,6 @@ class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
'device_type', 'device_role', 'tenant', 'platform', 'site', 'rack', 'status', 'cluster', '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: class Meta:
ordering = ('_name', 'pk') # Name may be null ordering = ('_name', 'pk') # Name may be null
unique_together = ( unique_together = (
@ -881,7 +871,7 @@ class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
return Device.objects.filter(parent_bay__device=self.pk) return Device.objects.filter(parent_bay__device=self.pk)
def get_status_class(self): 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', 'color', 'length', 'length_unit',
] ]
STATUS_CLASS_MAP = {
CableStatusChoices.STATUS_CONNECTED: 'success',
CableStatusChoices.STATUS_PLANNED: 'info',
CableStatusChoices.STATUS_DECOMMISSIONING: 'warning',
}
class Meta: class Meta:
ordering = ['pk'] ordering = ['pk']
unique_together = ( unique_together = (
@ -1159,7 +1143,7 @@ class Cable(ChangeLoggedModel, CustomFieldModel):
) )
def get_status_class(self): 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): def get_compatible_types(self):
""" """

View File

@ -156,18 +156,6 @@ class PowerFeed(ChangeLoggedModel, CableTermination, CustomFieldModel):
'available_power', '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: class Meta:
ordering = ['power_panel', 'name'] ordering = ['power_panel', 'name']
unique_together = ['power_panel', 'name'] unique_together = ['power_panel', 'name']
@ -225,7 +213,7 @@ class PowerFeed(ChangeLoggedModel, CableTermination, CustomFieldModel):
return self.power_panel return self.power_panel
def get_type_class(self): 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): def get_status_class(self):
return self.STATUS_CLASS_MAP.get(self.status) return PowerFeedStatusChoices.CSS_CLASSES.get(self.status)

View File

@ -276,14 +276,6 @@ class Rack(ChangeLoggedModel, CustomFieldModel):
'outer_depth', 'outer_unit', '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: class Meta:
ordering = ('site', 'group', '_name', 'pk') # (site, group, name) may be non-unique ordering = ('site', 'group', '_name', 'pk') # (site, group, name) may be non-unique
unique_together = ( unique_together = (
@ -379,7 +371,7 @@ class Rack(ChangeLoggedModel, CustomFieldModel):
return self.name return self.name
def get_status_class(self): 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): def get_rack_units(self, user=None, face=DeviceFaceChoices.FACE_FRONT, exclude=None, expand_devices=True):
""" """

View File

@ -199,14 +199,6 @@ class Site(ChangeLoggedModel, CustomFieldModel):
'shipping_address', 'latitude', 'longitude', 'contact_name', 'contact_phone', 'contact_email', '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: class Meta:
ordering = ('_name',) ordering = ('_name',)
@ -238,4 +230,4 @@ class Site(ChangeLoggedModel, CustomFieldModel):
) )
def get_status_class(self): def get_status_class(self):
return self.STATUS_CLASS_MAP.get(self.status) return SiteStatusChoices.CSS_CLASSES.get(self.status)

View File

@ -99,13 +99,13 @@ class LogLevelChoices(ChoiceSet):
(LOG_FAILURE, 'Failure'), (LOG_FAILURE, 'Failure'),
) )
CLASS_MAP = ( CSS_CLASSES = {
(LOG_DEFAULT, 'default'), LOG_DEFAULT: 'default',
(LOG_SUCCESS, 'success'), LOG_SUCCESS: 'success',
(LOG_INFO, 'info'), LOG_INFO: 'info',
(LOG_WARNING, 'warning'), LOG_WARNING: 'warning',
(LOG_FAILURE, 'danger'), LOG_FAILURE: 'danger',
) }
# #

View File

@ -13,5 +13,5 @@ def log_level(level):
""" """
return { return {
'name': LogLevelChoices.as_dict()[level], 'name': LogLevelChoices.as_dict()[level],
'class': dict(LogLevelChoices.CLASS_MAP)[level] 'class': LogLevelChoices.CSS_CLASSES.get(level)
} }

View File

@ -30,6 +30,13 @@ class PrefixStatusChoices(ChoiceSet):
(STATUS_DEPRECATED, 'Deprecated'), (STATUS_DEPRECATED, 'Deprecated'),
) )
CSS_CLASSES = {
STATUS_CONTAINER: 'default',
STATUS_ACTIVE: 'primary',
STATUS_RESERVED: 'info',
STATUS_DEPRECATED: 'danger',
}
# #
# IPAddresses # IPAddresses
@ -51,6 +58,14 @@ class IPAddressStatusChoices(ChoiceSet):
(STATUS_SLAAC, 'SLAAC'), (STATUS_SLAAC, 'SLAAC'),
) )
CSS_CLASSES = {
STATUS_ACTIVE: 'primary',
STATUS_RESERVED: 'info',
STATUS_DEPRECATED: 'danger',
STATUS_DHCP: 'success',
STATUS_SLAAC: 'success',
}
class IPAddressRoleChoices(ChoiceSet): class IPAddressRoleChoices(ChoiceSet):
@ -74,6 +89,17 @@ class IPAddressRoleChoices(ChoiceSet):
(ROLE_CARP, 'CARP'), (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 # VLANs
@ -91,6 +117,12 @@ class VLANStatusChoices(ChoiceSet):
(STATUS_DEPRECATED, 'Deprecated'), (STATUS_DEPRECATED, 'Deprecated'),
) )
CSS_CLASSES = {
STATUS_ACTIVE: 'primary',
STATUS_RESERVED: 'info',
STATUS_DEPRECATED: 'danger',
}
# #
# Services # Services

View File

@ -420,13 +420,6 @@ class Prefix(ChangeLoggedModel, CustomFieldModel):
'site', 'vrf', 'tenant', 'vlan', 'status', 'role', 'is_pool', 'description', 'site', 'vrf', 'tenant', 'vlan', 'status', 'role', 'is_pool', 'description',
] ]
STATUS_CLASS_MAP = {
'container': 'default',
'active': 'primary',
'reserved': 'info',
'deprecated': 'danger',
}
class Meta: class Meta:
ordering = (F('vrf').asc(nulls_first=True), 'prefix', 'pk') # (vrf, prefix) may be non-unique ordering = (F('vrf').asc(nulls_first=True), 'prefix', 'pk') # (vrf, prefix) may be non-unique
verbose_name_plural = 'prefixes' verbose_name_plural = 'prefixes'
@ -507,7 +500,7 @@ class Prefix(ChangeLoggedModel, CustomFieldModel):
prefix_length = property(fset=_set_prefix_length) prefix_length = property(fset=_set_prefix_length)
def get_status_class(self): def get_status_class(self):
return self.STATUS_CLASS_MAP.get(self.status) return PrefixStatusChoices.CSS_CLASSES.get(self.status)
def get_duplicates(self): def get_duplicates(self):
return Prefix.objects.filter(vrf=self.vrf, prefix=str(self.prefix)).exclude(pk=self.pk) 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', '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: class Meta:
ordering = ('address', 'pk') # address may be non-unique ordering = ('address', 'pk') # address may be non-unique
verbose_name = 'IP address' verbose_name = 'IP address'
@ -840,10 +814,10 @@ class IPAddress(ChangeLoggedModel, CustomFieldModel):
mask_length = property(fset=_set_mask_length) mask_length = property(fset=_set_mask_length)
def get_status_class(self): 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): def get_role_class(self):
return self.ROLE_CLASS_MAP[self.role] return IPAddressRoleChoices.CSS_CLASSES.get(self.role)
class VLANGroup(ChangeLoggedModel): class VLANGroup(ChangeLoggedModel):
@ -967,12 +941,6 @@ class VLAN(ChangeLoggedModel, CustomFieldModel):
'site', 'group', 'tenant', 'status', 'role', 'description', 'site', 'group', 'tenant', 'status', 'role', 'description',
] ]
STATUS_CLASS_MAP = {
'active': 'primary',
'reserved': 'info',
'deprecated': 'danger',
}
class Meta: class Meta:
ordering = ('site', 'group', 'vid', 'pk') # (site, group, vid) may be non-unique ordering = ('site', 'group', 'vid', 'pk') # (site, group, vid) may be non-unique
unique_together = [ unique_together = [
@ -1013,7 +981,7 @@ class VLAN(ChangeLoggedModel, CustomFieldModel):
return f'{self.name} ({self.vid})' return f'{self.name} ({self.vid})'
def get_status_class(self): def get_status_class(self):
return self.STATUS_CLASS_MAP[self.status] return VLANStatusChoices.CSS_CLASSES.get(self.status)
def get_interfaces(self): def get_interfaces(self):
# Return all device interfaces assigned to this VLAN # Return all device interfaces assigned to this VLAN

View File

@ -22,3 +22,12 @@ class VirtualMachineStatusChoices(ChoiceSet):
(STATUS_FAILED, 'Failed'), (STATUS_FAILED, 'Failed'),
(STATUS_DECOMMISSIONING, 'Decommissioning'), (STATUS_DECOMMISSIONING, 'Decommissioning'),
) )
CSS_CLASSES = {
STATUS_OFFLINE: 'warning',
STATUS_ACTIVE: 'success',
STATUS_PLANNED: 'info',
STATUS_STAGED: 'primary',
STATUS_FAILED: 'danger',
STATUS_DECOMMISSIONING: 'warning',
}

View File

@ -287,15 +287,6 @@ class VirtualMachine(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
'cluster', 'tenant', 'platform', 'status', 'role', 'vcpus', 'memory', 'disk', 'cluster', 'tenant', 'platform', 'status', 'role', 'vcpus', 'memory', 'disk',
] ]
STATUS_CLASS_MAP = {
VirtualMachineStatusChoices.STATUS_OFFLINE: 'warning',
VirtualMachineStatusChoices.STATUS_ACTIVE: 'success',
VirtualMachineStatusChoices.STATUS_PLANNED: 'info',
VirtualMachineStatusChoices.STATUS_STAGED: 'primary',
VirtualMachineStatusChoices.STATUS_FAILED: 'danger',
VirtualMachineStatusChoices.STATUS_DECOMMISSIONING: 'warning',
}
class Meta: class Meta:
ordering = ('name', 'pk') # Name may be non-unique ordering = ('name', 'pk') # Name may be non-unique
unique_together = [ unique_together = [
@ -355,7 +346,7 @@ class VirtualMachine(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
) )
def get_status_class(self): def get_status_class(self):
return self.STATUS_CLASS_MAP.get(self.status) return VirtualMachineStatusChoices.CSS_CLASSES.get(self.status)
@property @property
def primary_ip(self): def primary_ip(self):