diff --git a/netbox/circuits/tables/__init__.py b/netbox/circuits/tables/__init__.py new file mode 100644 index 000000000..b61c13cae --- /dev/null +++ b/netbox/circuits/tables/__init__.py @@ -0,0 +1,3 @@ +from .circuits import * +from .columns import * +from .providers import * diff --git a/netbox/circuits/tables.py b/netbox/circuits/tables/circuits.py similarity index 52% rename from netbox/circuits/tables.py rename to netbox/circuits/tables/circuits.py index 56da24842..175d1eec8 100644 --- a/netbox/circuits/tables.py +++ b/netbox/circuits/tables/circuits.py @@ -1,15 +1,13 @@ import django_tables2 as tables -from django_tables2.utils import Accessor +from circuits.models import * from netbox.tables import NetBoxTable, columns from tenancy.tables import TenantColumn -from .models import * +from .columns import CommitRateColumn __all__ = ( 'CircuitTable', 'CircuitTypeTable', - 'ProviderTable', - 'ProviderNetworkTable', ) @@ -22,81 +20,6 @@ CIRCUITTERMINATION_LINK = """ """ -# -# Table columns -# - -class CommitRateColumn(tables.TemplateColumn): - """ - Humanize the commit rate in the column view - """ - - template_code = """ - {% load helpers %} - {{ record.commit_rate|humanize_speed }} - """ - - def __init__(self, *args, **kwargs): - super().__init__(template_code=self.template_code, *args, **kwargs) - - def value(self, value): - return str(value) if value else None - - -# -# Providers -# - -class ProviderTable(NetBoxTable): - name = tables.Column( - linkify=True - ) - circuit_count = tables.Column( - accessor=Accessor('count_circuits'), - verbose_name='Circuits' - ) - comments = columns.MarkdownColumn() - tags = columns.TagColumn( - url_name='circuits:provider_list' - ) - - class Meta(NetBoxTable.Meta): - model = Provider - fields = ( - 'pk', 'id', 'name', 'asn', 'account', 'portal_url', 'noc_contact', 'admin_contact', 'circuit_count', - 'comments', 'tags', 'created', 'last_updated', - ) - default_columns = ('pk', 'name', 'asn', 'account', 'circuit_count') - - -# -# Provider networks -# - -class ProviderNetworkTable(NetBoxTable): - name = tables.Column( - linkify=True - ) - provider = tables.Column( - linkify=True - ) - comments = columns.MarkdownColumn() - tags = columns.TagColumn( - url_name='circuits:providernetwork_list' - ) - - class Meta(NetBoxTable.Meta): - model = ProviderNetwork - fields = ( - 'pk', 'id', 'name', 'provider', 'service_id', 'description', 'comments', 'created', 'last_updated', 'tags', - ) - default_columns = ('pk', 'name', 'provider', 'service_id', 'description') - - -# -# Circuit types -# - class CircuitTypeTable(NetBoxTable): name = tables.Column( linkify=True @@ -116,10 +39,6 @@ class CircuitTypeTable(NetBoxTable): default_columns = ('pk', 'name', 'circuit_count', 'description', 'slug') -# -# Circuits -# - class CircuitTable(NetBoxTable): cid = tables.Column( linkify=True, diff --git a/netbox/circuits/tables/columns.py b/netbox/circuits/tables/columns.py new file mode 100644 index 000000000..d7a5ffd28 --- /dev/null +++ b/netbox/circuits/tables/columns.py @@ -0,0 +1,21 @@ +import django_tables2 as tables + +__all__ = ( + 'CommitRateColumn', +) + + +class CommitRateColumn(tables.TemplateColumn): + """ + Humanize the commit rate in the column view + """ + template_code = """ + {% load helpers %} + {{ record.commit_rate|humanize_speed }} + """ + + def __init__(self, *args, **kwargs): + super().__init__(template_code=self.template_code, *args, **kwargs) + + def value(self, value): + return str(value) if value else None diff --git a/netbox/circuits/tables/providers.py b/netbox/circuits/tables/providers.py new file mode 100644 index 000000000..9ffdf54e3 --- /dev/null +++ b/netbox/circuits/tables/providers.py @@ -0,0 +1,52 @@ +import django_tables2 as tables +from django_tables2.utils import Accessor + +from circuits.models import * +from netbox.tables import NetBoxTable, columns + +__all__ = ( + 'ProviderTable', + 'ProviderNetworkTable', +) + + +class ProviderTable(NetBoxTable): + name = tables.Column( + linkify=True + ) + circuit_count = tables.Column( + accessor=Accessor('count_circuits'), + verbose_name='Circuits' + ) + comments = columns.MarkdownColumn() + tags = columns.TagColumn( + url_name='circuits:provider_list' + ) + + class Meta(NetBoxTable.Meta): + model = Provider + fields = ( + 'pk', 'id', 'name', 'asn', 'account', 'portal_url', 'noc_contact', 'admin_contact', 'circuit_count', + 'comments', 'tags', 'created', 'last_updated', + ) + default_columns = ('pk', 'name', 'asn', 'account', 'circuit_count') + + +class ProviderNetworkTable(NetBoxTable): + name = tables.Column( + linkify=True + ) + provider = tables.Column( + linkify=True + ) + comments = columns.MarkdownColumn() + tags = columns.TagColumn( + url_name='circuits:providernetwork_list' + ) + + class Meta(NetBoxTable.Meta): + model = ProviderNetwork + fields = ( + 'pk', 'id', 'name', 'provider', 'service_id', 'description', 'comments', 'created', 'last_updated', 'tags', + ) + default_columns = ('pk', 'name', 'provider', 'service_id', 'description') diff --git a/netbox/dcim/tables/devicetypes.py b/netbox/dcim/tables/devicetypes.py index 21318ecd4..9995ab088 100644 --- a/netbox/dcim/tables/devicetypes.py +++ b/netbox/dcim/tables/devicetypes.py @@ -1,5 +1,4 @@ import django_tables2 as tables -from django_tables2.utils import Accessor from dcim.models import ( ConsolePortTemplate, ConsoleServerPortTemplate, DeviceBayTemplate, DeviceType, FrontPortTemplate, InterfaceTemplate, diff --git a/netbox/extras/tables/__init__.py b/netbox/extras/tables/__init__.py new file mode 100644 index 000000000..fdcd6bb1b --- /dev/null +++ b/netbox/extras/tables/__init__.py @@ -0,0 +1 @@ +from .tables import * diff --git a/netbox/extras/tables.py b/netbox/extras/tables/tables.py similarity index 87% rename from netbox/extras/tables.py rename to netbox/extras/tables/tables.py index 15dd0400e..db05705d2 100644 --- a/netbox/extras/tables.py +++ b/netbox/extras/tables/tables.py @@ -1,8 +1,9 @@ import django_tables2 as tables from django.conf import settings +from extras.models import * from netbox.tables import NetBoxTable, columns -from .models import * +from .template_code import * __all__ = ( 'ConfigContextTable', @@ -17,32 +18,6 @@ __all__ = ( 'WebhookTable', ) -CONFIGCONTEXT_ACTIONS = """ -{% if perms.extras.change_configcontext %} - -{% endif %} -{% if perms.extras.delete_configcontext %} - -{% endif %} -""" - -OBJECTCHANGE_FULL_NAME = """ -{% load helpers %} -{{ record.user.get_full_name|placeholder }} -""" - -OBJECTCHANGE_OBJECT = """ -{% if record.changed_object and record.changed_object.get_absolute_url %} - {{ record.object_repr }} -{% else %} - {{ record.object_repr }} -{% endif %} -""" - -OBJECTCHANGE_REQUEST_ID = """ -{{ value }} -""" - # # Custom fields diff --git a/netbox/extras/tables/template_code.py b/netbox/extras/tables/template_code.py new file mode 100644 index 000000000..4eec85bdd --- /dev/null +++ b/netbox/extras/tables/template_code.py @@ -0,0 +1,25 @@ +CONFIGCONTEXT_ACTIONS = """ +{% if perms.extras.change_configcontext %} + +{% endif %} +{% if perms.extras.delete_configcontext %} + +{% endif %} +""" + +OBJECTCHANGE_FULL_NAME = """ +{% load helpers %} +{{ record.user.get_full_name|placeholder }} +""" + +OBJECTCHANGE_OBJECT = """ +{% if record.changed_object and record.changed_object.get_absolute_url %} + {{ record.object_repr }} +{% else %} + {{ record.object_repr }} +{% endif %} +""" + +OBJECTCHANGE_REQUEST_ID = """ +{{ value }} +""" diff --git a/netbox/tenancy/tables/__init__.py b/netbox/tenancy/tables/__init__.py new file mode 100644 index 000000000..f74617c36 --- /dev/null +++ b/netbox/tenancy/tables/__init__.py @@ -0,0 +1,3 @@ +from .columns import * +from .contacts import * +from .tenants import * diff --git a/netbox/tenancy/tables/columns.py b/netbox/tenancy/tables/columns.py new file mode 100644 index 000000000..bb5aba5de --- /dev/null +++ b/netbox/tenancy/tables/columns.py @@ -0,0 +1,26 @@ +import django_tables2 as tables + +__all__ = ( + 'TenantColumn', +) + + +class TenantColumn(tables.TemplateColumn): + """ + Include the tenant description. + """ + template_code = """ + {% if record.tenant %} + {{ record.tenant }} + {% elif record.vrf.tenant %} + {{ record.vrf.tenant }}* + {% else %} + — + {% endif %} + """ + + def __init__(self, *args, **kwargs): + super().__init__(template_code=self.template_code, *args, **kwargs) + + def value(self, value): + return str(value) if value else None diff --git a/netbox/tenancy/tables.py b/netbox/tenancy/tables/contacts.py similarity index 56% rename from netbox/tenancy/tables.py rename to netbox/tenancy/tables/contacts.py index 4f90ee01f..09f418473 100644 --- a/netbox/tenancy/tables.py +++ b/netbox/tenancy/tables/contacts.py @@ -1,92 +1,17 @@ import django_tables2 as tables from netbox.tables import NetBoxTable, columns +from tenancy.models import * from utilities.tables import linkify_phone -from .models import * __all__ = ( 'ContactAssignmentTable', 'ContactGroupTable', 'ContactRoleTable', 'ContactTable', - 'TenantColumn', - 'TenantGroupTable', - 'TenantTable', ) -# -# Table columns -# - -class TenantColumn(tables.TemplateColumn): - """ - Include the tenant description. - """ - template_code = """ - {% if record.tenant %} - {{ record.tenant }} - {% elif record.vrf.tenant %} - {{ record.vrf.tenant }}* - {% else %} - — - {% endif %} - """ - - def __init__(self, *args, **kwargs): - super().__init__(template_code=self.template_code, *args, **kwargs) - - def value(self, value): - return str(value) if value else None - - -# -# Tenants -# - -class TenantGroupTable(NetBoxTable): - name = columns.MPTTColumn( - linkify=True - ) - tenant_count = columns.LinkedCountColumn( - viewname='tenancy:tenant_list', - url_params={'group_id': 'pk'}, - verbose_name='Tenants' - ) - tags = columns.TagColumn( - url_name='tenancy:tenantgroup_list' - ) - - class Meta(NetBoxTable.Meta): - model = TenantGroup - fields = ( - 'pk', 'id', 'name', 'tenant_count', 'description', 'slug', 'tags', 'created', 'last_updated', 'actions', - ) - default_columns = ('pk', 'name', 'tenant_count', 'description') - - -class TenantTable(NetBoxTable): - name = tables.Column( - linkify=True - ) - group = tables.Column( - linkify=True - ) - comments = columns.MarkdownColumn() - tags = columns.TagColumn( - url_name='tenancy:tenant_list' - ) - - class Meta(NetBoxTable.Meta): - model = Tenant - fields = ('pk', 'id', 'name', 'slug', 'group', 'description', 'comments', 'tags', 'created', 'last_updated',) - default_columns = ('pk', 'name', 'group', 'description') - - -# -# Contacts -# - class ContactGroupTable(NetBoxTable): name = columns.MPTTColumn( linkify=True diff --git a/netbox/tenancy/tables/tenants.py b/netbox/tenancy/tables/tenants.py new file mode 100644 index 000000000..a5931052f --- /dev/null +++ b/netbox/tenancy/tables/tenants.py @@ -0,0 +1,48 @@ +import django_tables2 as tables + +from netbox.tables import NetBoxTable, columns +from tenancy.models import * + +__all__ = ( + 'TenantGroupTable', + 'TenantTable', +) + + +class TenantGroupTable(NetBoxTable): + name = columns.MPTTColumn( + linkify=True + ) + tenant_count = columns.LinkedCountColumn( + viewname='tenancy:tenant_list', + url_params={'group_id': 'pk'}, + verbose_name='Tenants' + ) + tags = columns.TagColumn( + url_name='tenancy:tenantgroup_list' + ) + + class Meta(NetBoxTable.Meta): + model = TenantGroup + fields = ( + 'pk', 'id', 'name', 'tenant_count', 'description', 'slug', 'tags', 'created', 'last_updated', 'actions', + ) + default_columns = ('pk', 'name', 'tenant_count', 'description') + + +class TenantTable(NetBoxTable): + name = tables.Column( + linkify=True + ) + group = tables.Column( + linkify=True + ) + comments = columns.MarkdownColumn() + tags = columns.TagColumn( + url_name='tenancy:tenant_list' + ) + + class Meta(NetBoxTable.Meta): + model = Tenant + fields = ('pk', 'id', 'name', 'slug', 'group', 'description', 'comments', 'tags', 'created', 'last_updated',) + default_columns = ('pk', 'name', 'group', 'description') diff --git a/netbox/virtualization/tables/__init__.py b/netbox/virtualization/tables/__init__.py new file mode 100644 index 000000000..dc1e7eb20 --- /dev/null +++ b/netbox/virtualization/tables/__init__.py @@ -0,0 +1,2 @@ +from .clusters import * +from .virtualmachines import * diff --git a/netbox/virtualization/tables/clusters.py b/netbox/virtualization/tables/clusters.py new file mode 100644 index 000000000..ecc0d69ce --- /dev/null +++ b/netbox/virtualization/tables/clusters.py @@ -0,0 +1,88 @@ +import django_tables2 as tables + +from netbox.tables import NetBoxTable, columns +from virtualization.models import Cluster, ClusterGroup, ClusterType + +__all__ = ( + 'ClusterTable', + 'ClusterGroupTable', + 'ClusterTypeTable', +) + + +class ClusterTypeTable(NetBoxTable): + name = tables.Column( + linkify=True + ) + cluster_count = tables.Column( + verbose_name='Clusters' + ) + tags = columns.TagColumn( + url_name='virtualization:clustertype_list' + ) + + class Meta(NetBoxTable.Meta): + model = ClusterType + fields = ( + 'pk', 'id', 'name', 'slug', 'cluster_count', 'description', 'created', 'last_updated', 'tags', 'actions', + ) + default_columns = ('pk', 'name', 'cluster_count', 'description') + + +class ClusterGroupTable(NetBoxTable): + name = tables.Column( + linkify=True + ) + cluster_count = tables.Column( + verbose_name='Clusters' + ) + tags = columns.TagColumn( + url_name='virtualization:clustergroup_list' + ) + + class Meta(NetBoxTable.Meta): + model = ClusterGroup + fields = ( + 'pk', 'id', 'name', 'slug', 'cluster_count', 'description', 'tags', 'created', 'last_updated', 'actions', + ) + default_columns = ('pk', 'name', 'cluster_count', 'description') + + +class ClusterTable(NetBoxTable): + name = tables.Column( + linkify=True + ) + type = tables.Column( + linkify=True + ) + group = tables.Column( + linkify=True + ) + tenant = tables.Column( + linkify=True + ) + site = tables.Column( + linkify=True + ) + device_count = columns.LinkedCountColumn( + viewname='dcim:device_list', + url_params={'cluster_id': 'pk'}, + verbose_name='Devices' + ) + vm_count = columns.LinkedCountColumn( + viewname='virtualization:virtualmachine_list', + url_params={'cluster_id': 'pk'}, + verbose_name='VMs' + ) + comments = columns.MarkdownColumn() + tags = columns.TagColumn( + url_name='virtualization:cluster_list' + ) + + class Meta(NetBoxTable.Meta): + model = Cluster + fields = ( + 'pk', 'id', 'name', 'type', 'group', 'tenant', 'site', 'comments', 'device_count', 'vm_count', 'tags', + 'created', 'last_updated', + ) + default_columns = ('pk', 'name', 'type', 'group', 'tenant', 'site', 'device_count', 'vm_count') diff --git a/netbox/virtualization/tables.py b/netbox/virtualization/tables/virtualmachines.py similarity index 58% rename from netbox/virtualization/tables.py rename to netbox/virtualization/tables/virtualmachines.py index 4dc6bb917..a2c8a4151 100644 --- a/netbox/virtualization/tables.py +++ b/netbox/virtualization/tables/virtualmachines.py @@ -3,12 +3,9 @@ import django_tables2 as tables from dcim.tables.devices import BaseInterfaceTable from netbox.tables import NetBoxTable, columns from tenancy.tables import TenantColumn -from .models import Cluster, ClusterGroup, ClusterType, VirtualMachine, VMInterface +from virtualization.models import VirtualMachine, VMInterface __all__ = ( - 'ClusterTable', - 'ClusterGroupTable', - 'ClusterTypeTable', 'VirtualMachineTable', 'VirtualMachineVMInterfaceTable', 'VMInterfaceTable', @@ -23,96 +20,6 @@ VMINTERFACE_BUTTONS = """ """ -# -# Cluster types -# - -class ClusterTypeTable(NetBoxTable): - name = tables.Column( - linkify=True - ) - cluster_count = tables.Column( - verbose_name='Clusters' - ) - tags = columns.TagColumn( - url_name='virtualization:clustertype_list' - ) - - class Meta(NetBoxTable.Meta): - model = ClusterType - fields = ( - 'pk', 'id', 'name', 'slug', 'cluster_count', 'description', 'created', 'last_updated', 'tags', 'actions', - ) - default_columns = ('pk', 'name', 'cluster_count', 'description') - - -# -# Cluster groups -# - -class ClusterGroupTable(NetBoxTable): - name = tables.Column( - linkify=True - ) - cluster_count = tables.Column( - verbose_name='Clusters' - ) - tags = columns.TagColumn( - url_name='virtualization:clustergroup_list' - ) - - class Meta(NetBoxTable.Meta): - model = ClusterGroup - fields = ( - 'pk', 'id', 'name', 'slug', 'cluster_count', 'description', 'tags', 'created', 'last_updated', 'actions', - ) - default_columns = ('pk', 'name', 'cluster_count', 'description') - - -# -# Clusters -# - -class ClusterTable(NetBoxTable): - name = tables.Column( - linkify=True - ) - type = tables.Column( - linkify=True - ) - group = tables.Column( - linkify=True - ) - tenant = tables.Column( - linkify=True - ) - site = tables.Column( - linkify=True - ) - device_count = columns.LinkedCountColumn( - viewname='dcim:device_list', - url_params={'cluster_id': 'pk'}, - verbose_name='Devices' - ) - vm_count = columns.LinkedCountColumn( - viewname='virtualization:virtualmachine_list', - url_params={'cluster_id': 'pk'}, - verbose_name='VMs' - ) - comments = columns.MarkdownColumn() - tags = columns.TagColumn( - url_name='virtualization:cluster_list' - ) - - class Meta(NetBoxTable.Meta): - model = Cluster - fields = ( - 'pk', 'id', 'name', 'type', 'group', 'tenant', 'site', 'comments', 'device_count', 'vm_count', 'tags', - 'created', 'last_updated', - ) - default_columns = ('pk', 'name', 'type', 'group', 'tenant', 'site', 'device_count', 'vm_count') - - # # Virtual machines # diff --git a/netbox/wireless/tables/__init__.py b/netbox/wireless/tables/__init__.py new file mode 100644 index 000000000..d01a5baf8 --- /dev/null +++ b/netbox/wireless/tables/__init__.py @@ -0,0 +1,2 @@ +from .wirelesslan import * +from .wirelesslink import * diff --git a/netbox/wireless/tables.py b/netbox/wireless/tables/wirelesslan.py similarity index 63% rename from netbox/wireless/tables.py rename to netbox/wireless/tables/wirelesslan.py index 8dd81dffd..9955d4ac4 100644 --- a/netbox/wireless/tables.py +++ b/netbox/wireless/tables/wirelesslan.py @@ -2,12 +2,12 @@ import django_tables2 as tables from dcim.models import Interface from netbox.tables import NetBoxTable, columns -from .models import * +from wireless.models import * __all__ = ( - 'WirelessLANTable', 'WirelessLANGroupTable', - 'WirelessLinkTable', + 'WirelessLANInterfacesTable', + 'WirelessLANTable', ) @@ -67,39 +67,3 @@ class WirelessLANInterfacesTable(NetBoxTable): model = Interface fields = ('pk', 'device', 'name', 'rf_role', 'rf_channel') default_columns = ('pk', 'device', 'name', 'rf_role', 'rf_channel') - - -class WirelessLinkTable(NetBoxTable): - id = tables.Column( - linkify=True, - verbose_name='ID' - ) - status = columns.ChoiceFieldColumn() - device_a = tables.Column( - accessor=tables.A('interface_a__device'), - linkify=True - ) - interface_a = tables.Column( - linkify=True - ) - device_b = tables.Column( - accessor=tables.A('interface_b__device'), - linkify=True - ) - interface_b = tables.Column( - linkify=True - ) - tags = columns.TagColumn( - url_name='wireless:wirelesslink_list' - ) - - class Meta(NetBoxTable.Meta): - model = WirelessLink - fields = ( - 'pk', 'id', 'status', 'device_a', 'interface_a', 'device_b', 'interface_b', 'ssid', 'description', - 'auth_type', 'auth_cipher', 'auth_psk', 'tags', 'created', 'last_updated', - ) - default_columns = ( - 'pk', 'id', 'status', 'device_a', 'interface_a', 'device_b', 'interface_b', 'ssid', 'auth_type', - 'description', - ) diff --git a/netbox/wireless/tables/wirelesslink.py b/netbox/wireless/tables/wirelesslink.py new file mode 100644 index 000000000..72037c4d9 --- /dev/null +++ b/netbox/wireless/tables/wirelesslink.py @@ -0,0 +1,44 @@ +import django_tables2 as tables + +from netbox.tables import NetBoxTable, columns +from wireless.models import * + +__all__ = ( + 'WirelessLinkTable', +) + + +class WirelessLinkTable(NetBoxTable): + id = tables.Column( + linkify=True, + verbose_name='ID' + ) + status = columns.ChoiceFieldColumn() + device_a = tables.Column( + accessor=tables.A('interface_a__device'), + linkify=True + ) + interface_a = tables.Column( + linkify=True + ) + device_b = tables.Column( + accessor=tables.A('interface_b__device'), + linkify=True + ) + interface_b = tables.Column( + linkify=True + ) + tags = columns.TagColumn( + url_name='wireless:wirelesslink_list' + ) + + class Meta(NetBoxTable.Meta): + model = WirelessLink + fields = ( + 'pk', 'id', 'status', 'device_a', 'interface_a', 'device_b', 'interface_b', 'ssid', 'description', + 'auth_type', 'auth_cipher', 'auth_psk', 'tags', 'created', 'last_updated', + ) + default_columns = ( + 'pk', 'id', 'status', 'device_a', 'interface_a', 'device_b', 'interface_b', 'ssid', 'auth_type', + 'description', + )