move attrs to separate file
CI / build (20.x, 3.12) (push) Failing after 12s
CI / build (20.x, 3.13) (push) Failing after 10s
CI / build (20.x, 3.14) (push) Failing after 10s

This commit is contained in:
Arthur
2026-03-18 15:04:07 -07:00
parent ca76d37ffe
commit 8816af1389
2 changed files with 26 additions and 22 deletions
+25
View File
@@ -0,0 +1,25 @@
from django.template.loader import render_to_string
from netbox.ui import attrs
class VRFDisplayAttr(attrs.ObjectAttribute):
"""
Renders a VRF reference, displaying 'Global' when no VRF is assigned.
"""
template_name = 'ipam/attrs/vrf.html'
def render(self, obj, context):
value = self.get_value(obj)
return render_to_string(self.template_name, {
**self.get_context(obj, context),
'name': context.get('name', ''),
'value': value,
})
class VRFDisplayWithRDAttr(VRFDisplayAttr):
"""
Renders a VRF reference with its route distinguisher.
"""
template_name = 'ipam/attrs/vrf_with_rd.html'
+1 -22
View File
@@ -1,31 +1,10 @@
from django.contrib.contenttypes.models import ContentType
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from netbox.ui import actions, attrs, panels
class VRFDisplayAttr(attrs.ObjectAttribute):
"""
Renders a VRF reference, displaying 'Global' when no VRF is assigned.
"""
template_name = 'ipam/attrs/vrf.html'
def render(self, obj, context):
value = self.get_value(obj)
return render_to_string(self.template_name, {
**self.get_context(obj, context),
'name': context.get('name', ''),
'value': value,
})
class VRFDisplayWithRDAttr(VRFDisplayAttr):
"""
Renders a VRF reference with its route distinguisher.
"""
template_name = 'ipam/attrs/vrf_with_rd.html'
from .attrs import VRFDisplayAttr, VRFDisplayWithRDAttr
class FHRPGroupAssignmentsPanel(panels.ObjectPanel):