diff --git a/netbox/ipam/tables/ip.py b/netbox/ipam/tables/ip.py index 399641422..dbbeb3454 100644 --- a/netbox/ipam/tables/ip.py +++ b/netbox/ipam/tables/ip.py @@ -6,6 +6,7 @@ from django_tables2.utils import Accessor from ipam.models import * from netbox.tables import NetBoxTable, columns from tenancy.tables import TenancyColumnsMixin, TenantColumn +from .template_code import * __all__ = ( 'AggregateTable', @@ -20,61 +21,6 @@ __all__ = ( AVAILABLE_LABEL = mark_safe('Available') -AGGREGATE_COPY_BUTTON = """ -{% copy_content record.pk prefix="aggregate_" %} -""" - -PREFIX_LINK = """ -{% if record.pk %} - {{ record.prefix }} -{% else %} - {{ record.prefix }} -{% endif %} -""" - -PREFIX_COPY_BUTTON = """ -{% copy_content record.pk prefix="prefix_" %} -""" - -PREFIX_LINK_WITH_DEPTH = """ -{% load helpers %} -{% if record.depth %} -
- {% for i in record.depth|as_range %} - - {% endfor %} -
-{% endif %} -""" + PREFIX_LINK - -IPADDRESS_LINK = """ -{% if record.pk %} - {{ record.address }} -{% elif perms.ipam.add_ipaddress %} - {% if record.0 <= 65536 %}{{ record.0 }}{% else %}Many{% endif %} IP{{ record.0|pluralize }} available -{% else %} - {% if record.0 <= 65536 %}{{ record.0 }}{% else %}Many{% endif %} IP{{ record.0|pluralize }} available -{% endif %} -""" - -IPADDRESS_COPY_BUTTON = """ -{% copy_content record.pk prefix="ipaddress_" %} -""" - -IPADDRESS_ASSIGN_LINK = """ -{{ record }} -""" - -VRF_LINK = """ -{% if value %} - {{ record.vrf }} -{% elif object.vrf %} - {{ object.vrf }} -{% else %} - Global -{% endif %} -""" - # # RIRs diff --git a/netbox/ipam/tables/template_code.py b/netbox/ipam/tables/template_code.py new file mode 100644 index 000000000..fb969345e --- /dev/null +++ b/netbox/ipam/tables/template_code.py @@ -0,0 +1,88 @@ +AGGREGATE_COPY_BUTTON = """ +{% copy_content record.pk prefix="aggregate_" %} +""" + +PREFIX_LINK = """ +{% if record.pk %} + {{ record.prefix }} +{% else %} + {{ record.prefix }} +{% endif %} +""" + +PREFIX_COPY_BUTTON = """ +{% copy_content record.pk prefix="prefix_" %} +""" + +PREFIX_LINK_WITH_DEPTH = """ +{% load helpers %} +{% if record.depth %} +
+ {% for i in record.depth|as_range %} + + {% endfor %} +
+{% endif %} +""" + PREFIX_LINK + +IPADDRESS_LINK = """ +{% if record.pk %} + {{ record.address }} +{% elif perms.ipam.add_ipaddress %} + {% if record.0 <= 65536 %}{{ record.0 }}{% else %}Many{% endif %} IP{{ record.0|pluralize }} available +{% else %} + {% if record.0 <= 65536 %}{{ record.0 }}{% else %}Many{% endif %} IP{{ record.0|pluralize }} available +{% endif %} +""" + +IPADDRESS_COPY_BUTTON = """ +{% copy_content record.pk prefix="ipaddress_" %} +""" + +IPADDRESS_ASSIGN_LINK = """ +{{ record }} +""" + +VRF_LINK = """ +{% if value %} + {{ record.vrf }} +{% elif object.vrf %} + {{ object.vrf }} +{% else %} + Global +{% endif %} +""" + +VLAN_LINK = """ +{% if record.pk %} + {{ record.vid }} +{% elif perms.ipam.add_vlan %} + {{ record.available }} VLAN{{ record.available|pluralize }} available +{% else %} + {{ record.available }} VLAN{{ record.available|pluralize }} available +{% endif %} +""" + +VLAN_PREFIXES = """ +{% for prefix in value.all %} + {{ prefix }}{% if not forloop.last %}
{% endif %} +{% endfor %} +""" + +VLANGROUP_BUTTONS = """ +{% with next_vid=record.get_next_available_vid %} + {% if next_vid and perms.ipam.add_vlan %} + + + + {% endif %} +{% endwith %} +""" + +VLAN_MEMBER_TAGGED = """ +{% if record.untagged_vlan_id == object.pk %} + +{% else %} + +{% endif %} +""" diff --git a/netbox/ipam/tables/vlans.py b/netbox/ipam/tables/vlans.py index d34ff5f45..e3d7c7e63 100644 --- a/netbox/ipam/tables/vlans.py +++ b/netbox/ipam/tables/vlans.py @@ -8,6 +8,7 @@ from ipam.models import * from netbox.tables import NetBoxTable, columns from tenancy.tables import TenancyColumnsMixin, TenantColumn from virtualization.models import VMInterface +from .template_code import * __all__ = ( 'InterfaceVLANTable', @@ -22,40 +23,6 @@ __all__ = ( AVAILABLE_LABEL = mark_safe('Available') -VLAN_LINK = """ -{% if record.pk %} - {{ record.vid }} -{% elif perms.ipam.add_vlan %} - {{ record.available }} VLAN{{ record.available|pluralize }} available -{% else %} - {{ record.available }} VLAN{{ record.available|pluralize }} available -{% endif %} -""" - -VLAN_PREFIXES = """ -{% for prefix in value.all %} - {{ prefix }}{% if not forloop.last %}
{% endif %} -{% endfor %} -""" - -VLANGROUP_BUTTONS = """ -{% with next_vid=record.get_next_available_vid %} - {% if next_vid and perms.ipam.add_vlan %} - - - - {% endif %} -{% endwith %} -""" - -VLAN_MEMBER_TAGGED = """ -{% if record.untagged_vlan_id == object.pk %} - -{% else %} - -{% endif %} -""" - # # VLAN groups diff --git a/netbox/netbox/tables/columns.py b/netbox/netbox/tables/columns.py index ee1420396..cf6e1f133 100644 --- a/netbox/netbox/tables/columns.py +++ b/netbox/netbox/tables/columns.py @@ -286,7 +286,8 @@ class ActionsColumn(tables.Column): if len(self.actions) == 1 or (self.split_actions and idx == 0): dropdown_class = attrs.css_class button = ( - f'' + f'' f'' ) @@ -303,7 +304,8 @@ class ActionsColumn(tables.Column): html += ( f'' f' {button}' - f' ' + f' ' f' {toggle_text}' f' ' f'' diff --git a/netbox/tenancy/tables/columns.py b/netbox/tenancy/tables/columns.py index ec73cac4a..005bcf737 100644 --- a/netbox/tenancy/tables/columns.py +++ b/netbox/tenancy/tables/columns.py @@ -2,6 +2,7 @@ from django.utils.translation import gettext_lazy as _ import django_tables2 as tables from netbox.tables import columns +from .template_code import * __all__ = ( 'ContactsColumnMixin', @@ -15,15 +16,7 @@ class TenantColumn(tables.TemplateColumn): """ Include the tenant description. """ - template_code = """ - {% if record.tenant %} - {{ record.tenant }} - {% elif record.vrf.tenant %} - {{ record.vrf.tenant }}* - {% else %} - — - {% endif %} - """ + template_code = TENANT_COLUMN def __init__(self, *args, **kwargs): super().__init__(template_code=self.template_code, *args, **kwargs) @@ -36,15 +29,7 @@ class TenantGroupColumn(tables.TemplateColumn): """ Include the tenant group description. """ - template_code = """ - {% if record.tenant and record.tenant.group %} - {{ record.tenant.group }} - {% elif record.vrf.tenant and record.vrf.tenant.group %} - {{ record.vrf.tenant.group }}* - {% else %} - — - {% endif %} - """ + template_code = TENANT_GROUP_COLUMN def __init__(self, accessor=tables.A('tenant__group'), *args, **kwargs): if 'verbose_name' not in kwargs: diff --git a/netbox/tenancy/tables/template_code.py b/netbox/tenancy/tables/template_code.py new file mode 100644 index 000000000..1d15a8708 --- /dev/null +++ b/netbox/tenancy/tables/template_code.py @@ -0,0 +1,19 @@ +TENANT_COLUMN = """ +{% if record.tenant %} + {{ record.tenant }} +{% elif record.vrf.tenant %} + {{ record.vrf.tenant }}* +{% else %} + — +{% endif %} +""" + +TENANT_GROUP_COLUMN = """ +{% if record.tenant and record.tenant.group %} + {{ record.tenant.group }} +{% elif record.vrf.tenant and record.vrf.tenant.group %} + {{ record.vrf.tenant.group }}* +{% else %} + — +{% endif %} +""" diff --git a/netbox/virtualization/tables/template_code.py b/netbox/virtualization/tables/template_code.py new file mode 100644 index 000000000..a6b7251f2 --- /dev/null +++ b/netbox/virtualization/tables/template_code.py @@ -0,0 +1,32 @@ +VMINTERFACE_BUTTONS = """ +{% if perms.virtualization.change_vminterface %} + + + + +{% endif %} +{% if perms.vpn.add_tunnel and not record.tunnel_termination %} + + + +{% elif perms.vpn.delete_tunneltermination and record.tunnel_termination %} + + + +{% endif %} +""" diff --git a/netbox/virtualization/tables/virtualmachines.py b/netbox/virtualization/tables/virtualmachines.py index fe7a66ac1..116051037 100644 --- a/netbox/virtualization/tables/virtualmachines.py +++ b/netbox/virtualization/tables/virtualmachines.py @@ -6,6 +6,7 @@ from netbox.tables import NetBoxTable, columns from tenancy.tables import ContactsColumnMixin, TenancyColumnsMixin from utilities.templatetags.helpers import humanize_megabytes from virtualization.models import VirtualDisk, VirtualMachine, VMInterface +from .template_code import * __all__ = ( 'VirtualDiskTable', @@ -15,39 +16,6 @@ __all__ = ( 'VMInterfaceTable', ) -VMINTERFACE_BUTTONS = """ -{% if perms.virtualization.change_vminterface %} - - - - -{% endif %} -{% if perms.vpn.add_tunnel and not record.tunnel_termination %} - - - -{% elif perms.vpn.delete_tunneltermination and record.tunnel_termination %} - - - -{% endif %} -""" - # # Virtual machines diff --git a/ruff.toml b/ruff.toml index 102de7747..12dac331e 100644 --- a/ruff.toml +++ b/ruff.toml @@ -8,5 +8,8 @@ extend-select = ["E1", "E2", "E3", "E501", "W"] ignore = ["F403", "F405"] preview = true +[lint.per-file-ignores] +"template_code.py" = ["E501"] + [format] quote-style = "single"