mirror of
https://github.com/drygdryg/netbox-plugin-interface-sync
synced 2024-11-25 18:10:52 +03:00
Do not display captions for empty attributes in tables
This commit is contained in:
parent
de4e730514
commit
eb01474779
@ -1,4 +1,4 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass, fields
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
config = settings.PLUGINS_CONFIG["netbox_interface_sync"]
|
config = settings.PLUGINS_CONFIG["netbox_interface_sync"]
|
||||||
@ -13,6 +13,8 @@ class ParentComparison:
|
|||||||
label: str
|
label: str
|
||||||
description: str
|
description: str
|
||||||
|
|
||||||
|
_non_printable_fields = ('id', 'name', 'is_template')
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
# Ignore some fields when comparing; ignore component name case and whitespaces
|
# Ignore some fields when comparing; ignore component name case and whitespaces
|
||||||
eq = (
|
eq = (
|
||||||
@ -28,8 +30,25 @@ class ParentComparison:
|
|||||||
# Ignore some fields when hashing; ignore component name case and whitespaces
|
# Ignore some fields when hashing; ignore component name case and whitespaces
|
||||||
return hash(self.name.lower().replace(" ", ""))
|
return hash(self.name.lower().replace(" ", ""))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __field_name_caption__(field_name: str):
|
||||||
|
field_captions = {
|
||||||
|
'type_display': 'Type',
|
||||||
|
'rear_port_position': 'Position'
|
||||||
|
}
|
||||||
|
return field_captions.get(field_name) or field_name.replace('_', ' ').capitalize()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"Label: {self.label}\nDescription: {self.description}"
|
fields_to_display = []
|
||||||
|
for field in fields(self):
|
||||||
|
if field.name in self._non_printable_fields:
|
||||||
|
continue
|
||||||
|
field_value = getattr(self, field.name)
|
||||||
|
if not field_value:
|
||||||
|
continue
|
||||||
|
field_name_display = self.__field_name_caption__(field.name)
|
||||||
|
fields_to_display.append(f'{field_name_display}: {field_value}')
|
||||||
|
return '\n'.join(fields_to_display)
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
@ -39,6 +58,8 @@ class ParentTypedComparison(ParentComparison):
|
|||||||
type: str
|
type: str
|
||||||
type_display: str
|
type_display: str
|
||||||
|
|
||||||
|
_non_printable_fields = ParentComparison._non_printable_fields + ('type',)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
eq = (
|
eq = (
|
||||||
(self.name.lower().replace(" ", "") == other.name.lower().replace(" ", ""))
|
(self.name.lower().replace(" ", "") == other.name.lower().replace(" ", ""))
|
||||||
@ -54,9 +75,6 @@ class ParentTypedComparison(ParentComparison):
|
|||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash((self.name.lower().replace(" ", ""), self.type))
|
return hash((self.name.lower().replace(" ", ""), self.type))
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f"{super().__str__()}\nType: {self.type_display}"
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class InterfaceComparison(ParentTypedComparison):
|
class InterfaceComparison(ParentTypedComparison):
|
||||||
@ -81,9 +99,6 @@ class InterfaceComparison(ParentTypedComparison):
|
|||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash((self.name.lower().replace(" ", ""), self.type))
|
return hash((self.name.lower().replace(" ", ""), self.type))
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f"{super().__str__()}\nManagement only: {self.mgmt_only}"
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class FrontPortComparison(ParentTypedComparison):
|
class FrontPortComparison(ParentTypedComparison):
|
||||||
@ -111,9 +126,6 @@ class FrontPortComparison(ParentTypedComparison):
|
|||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash((self.name.lower().replace(" ", ""), self.type))
|
return hash((self.name.lower().replace(" ", ""), self.type))
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f"{super().__str__()}\nColor: {self.color}\nPosition: {self.rear_port_position}"
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class RearPortComparison(ParentTypedComparison):
|
class RearPortComparison(ParentTypedComparison):
|
||||||
@ -140,9 +152,6 @@ class RearPortComparison(ParentTypedComparison):
|
|||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash((self.name.lower().replace(" ", ""), self.type))
|
return hash((self.name.lower().replace(" ", ""), self.type))
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f"{super().__str__()}\nColor: {self.color}\nPositions: {self.positions}"
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, eq=False)
|
@dataclass(frozen=True, eq=False)
|
||||||
class ConsolePortComparison(ParentTypedComparison):
|
class ConsolePortComparison(ParentTypedComparison):
|
||||||
@ -183,9 +192,6 @@ class PowerPortComparison(ParentTypedComparison):
|
|||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash((self.name.lower().replace(" ", ""), self.type))
|
return hash((self.name.lower().replace(" ", ""), self.type))
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f"{super().__str__()}\nMaximum draw: {self.maximum_draw}\nAllocated draw: {self.allocated_draw}"
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class PowerOutletComparison(ParentTypedComparison):
|
class PowerOutletComparison(ParentTypedComparison):
|
||||||
@ -214,9 +220,6 @@ class PowerOutletComparison(ParentTypedComparison):
|
|||||||
(self.name.lower().replace(" ", ""), self.type, self.power_port_name)
|
(self.name.lower().replace(" ", ""), self.type, self.power_port_name)
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f"{super().__str__()}\nPower port name: {self.power_port_name}\nFeed leg: {self.feed_leg}"
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, eq=False)
|
@dataclass(frozen=True, eq=False)
|
||||||
class DeviceBayComparison(ParentComparison):
|
class DeviceBayComparison(ParentComparison):
|
||||||
|
Loading…
Reference in New Issue
Block a user