mirror of
https://github.com/netbox-community/netbox.git
synced 2026-03-21 20:18:38 -06:00
move attrs to separate file
This commit is contained in:
@@ -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,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):
|
||||
|
||||
Reference in New Issue
Block a user