panels.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from django.utils.translation import gettext_lazy as _
  2. from netbox.ui import attrs, panels
  3. class WirelessLANGroupPanel(panels.NestedGroupObjectPanel):
  4. pass
  5. class WirelessLANPanel(panels.ObjectAttributesPanel):
  6. ssid = attrs.TextAttr('ssid', label=_('SSID'))
  7. group = attrs.RelatedObjectAttr('group', linkify=True)
  8. status = attrs.ChoiceAttr('status')
  9. scope = attrs.GenericForeignKeyAttr('scope', linkify=True)
  10. description = attrs.TextAttr('description')
  11. vlan = attrs.RelatedObjectAttr('vlan', label=_('VLAN'), linkify=True)
  12. tenant = attrs.RelatedObjectAttr('tenant', linkify=True, grouped_by='group')
  13. class WirelessAuthenticationPanel(panels.ObjectAttributesPanel):
  14. title = _('Authentication')
  15. auth_type = attrs.ChoiceAttr('auth_type', label=_('Type'))
  16. auth_cipher = attrs.ChoiceAttr('auth_cipher', label=_('Cipher'))
  17. auth_psk = attrs.TemplatedAttr('auth_psk', label=_('PSK'), template_name='wireless/attrs/auth_psk.html')
  18. class WirelessLinkInterfacePanel(panels.ObjectPanel):
  19. template_name = 'wireless/panels/wirelesslink_interface.html'
  20. def __init__(self, interface_attr, title, **kwargs):
  21. super().__init__(**kwargs)
  22. self.interface_attr = interface_attr
  23. self.title = title
  24. def get_context(self, context):
  25. ctx = super().get_context(context)
  26. return {
  27. **ctx,
  28. 'interface': getattr(ctx['object'], self.interface_attr),
  29. }
  30. class WirelessLinkPropertiesPanel(panels.ObjectAttributesPanel):
  31. title = _('Link Properties')
  32. status = attrs.ChoiceAttr('status')
  33. ssid = attrs.TextAttr('ssid', label=_('SSID'))
  34. tenant = attrs.RelatedObjectAttr('tenant', linkify=True, grouped_by='group')
  35. description = attrs.TextAttr('description')
  36. distance = attrs.NumericAttr('distance', unit_accessor='get_distance_unit_display')