From 30578bfc9793225586e23af1e6f9a62406f145ca Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Fri, 13 Jan 2023 21:38:24 -0500 Subject: [PATCH] Additional table conversions (WIP) --- netbox/dcim/views.py | 21 -------- netbox/ipam/views.py | 54 +------------------ netbox/templates/dcim/interface.html | 11 ++-- netbox/templates/dcim/region.html | 10 ++-- netbox/templates/dcim/sitegroup.html | 10 ++-- netbox/templates/home.html | 7 +-- netbox/templates/htmx/table.html | 4 +- netbox/templates/inc/paginator_htmx.html | 16 +++--- netbox/templates/ipam/asn.html | 16 +++--- netbox/templates/ipam/fhrpgroup.html | 11 ++-- netbox/templates/ipam/rir.html | 12 ++--- netbox/templates/ipam/role.html | 28 +++------- netbox/templates/ipam/vlan.html | 32 ++++++----- .../virtualization/clustergroup.html | 10 ++-- .../templates/virtualization/clustertype.html | 10 ++-- .../templates/virtualization/vminterface.html | 15 ++---- .../templates/wireless/wirelesslangroup.html | 14 ++--- netbox/virtualization/views.py | 20 ------- netbox/wireless/views.py | 11 ---- 19 files changed, 93 insertions(+), 219 deletions(-) diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index 81b646383..e29aa612e 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -223,15 +223,8 @@ class RegionView(generic.ObjectView): child_regions_table = tables.RegionTable(child_regions) child_regions_table.columns.hide('actions') - sites = Site.objects.restrict(request.user, 'view').filter( - region=instance - ) - sites_table = tables.SiteTable(sites, user=request.user, exclude=('region',)) - sites_table.configure(request) - return { 'child_regions_table': child_regions_table, - 'sites_table': sites_table, } @@ -311,15 +304,8 @@ class SiteGroupView(generic.ObjectView): child_groups_table = tables.SiteGroupTable(child_groups) child_groups_table.columns.hide('actions') - sites = Site.objects.restrict(request.user, 'view').filter( - group=instance - ) - sites_table = tables.SiteTable(sites, user=request.user, exclude=('group',)) - sites_table.configure(request) - return { 'child_groups_table': child_groups_table, - 'sites_table': sites_table, } @@ -2456,12 +2442,6 @@ class InterfaceView(generic.ObjectView): orderable=False ) - # Get assigned IP addresses - ipaddress_table = AssignedIPAddressesTable( - data=instance.ip_addresses.restrict(request.user, 'view').prefetch_related('vrf', 'tenant'), - orderable=False - ) - # Get bridge interfaces bridge_interfaces = Interface.objects.restrict(request.user, 'view').filter(bridge=instance) bridge_interfaces_tables = tables.InterfaceTable( @@ -2494,7 +2474,6 @@ class InterfaceView(generic.ObjectView): return { 'vdc_table': vdc_table, - 'ipaddress_table': ipaddress_table, 'bridge_interfaces_table': bridge_interfaces_tables, 'child_interfaces_table': child_interfaces_tables, 'vlan_table': vlan_table, diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py index 130014f3f..4007b018c 100644 --- a/netbox/ipam/views.py +++ b/netbox/ipam/views.py @@ -5,11 +5,9 @@ from django.shortcuts import get_object_or_404, redirect, render from django.urls import reverse from django.utils.translation import gettext as _ -from circuits.models import Provider, Circuit -from circuits.tables import ProviderTable +from circuits.models import Provider from dcim.filtersets import InterfaceFilterSet from dcim.models import Interface, Site, Device -from dcim.tables import SiteTable from netbox.views import generic from utilities.utils import count_related from utilities.views import ViewTab, register_model_view @@ -167,17 +165,6 @@ class RIRListView(generic.ObjectListView): class RIRView(generic.ObjectView): queryset = RIR.objects.all() - def get_extra_context(self, request, instance): - aggregates = Aggregate.objects.restrict(request.user, 'view').filter(rir=instance).annotate( - child_count=RawSQL('SELECT COUNT(*) FROM ipam_prefix WHERE ipam_prefix.prefix <<= ipam_aggregate.prefix', ()) - ) - aggregates_table = tables.AggregateTable(aggregates, user=request.user, exclude=('rir', 'utilization')) - aggregates_table.configure(request) - - return { - 'aggregates_table': aggregates_table, - } - @register_model_view(RIR, 'edit') class RIREditView(generic.ObjectEditView): @@ -232,22 +219,11 @@ class ASNView(generic.ObjectView): queryset = ASN.objects.all() def get_extra_context(self, request, instance): - # Gather assigned Sites sites = instance.sites.restrict(request.user, 'view') - sites_table = SiteTable(sites, user=request.user) - sites_table.configure(request) - - # Gather assigned Providers - providers = instance.providers.restrict(request.user, 'view').annotate( - count_circuits=count_related(Circuit, 'provider') - ) - providers_table = ProviderTable(providers, user=request.user) - providers_table.configure(request) + providers = instance.providers.restrict(request.user, 'view') return { - 'sites_table': sites_table, 'sites_count': sites.count(), - 'providers_table': providers_table, 'providers_count': providers.count(), } @@ -392,18 +368,6 @@ class RoleListView(generic.ObjectListView): class RoleView(generic.ObjectView): queryset = Role.objects.all() - def get_extra_context(self, request, instance): - prefixes = Prefix.objects.restrict(request.user, 'view').filter( - role=instance - ) - - prefixes_table = tables.PrefixTable(prefixes, user=request.user, exclude=('role', 'utilization')) - prefixes_table.configure(request) - - return { - 'prefixes_table': prefixes_table, - } - @register_model_view(Role, 'edit') class RoleEditView(generic.ObjectEditView): @@ -888,17 +852,9 @@ class VLANGroupView(generic.ObjectView): vlans_table.columns.show('pk') vlans_table.configure(request) - # Compile permissions list for rendering the object table - permissions = { - 'add': request.user.has_perm('ipam.add_vlan'), - 'change': request.user.has_perm('ipam.change_vlan'), - 'delete': request.user.has_perm('ipam.delete_vlan'), - } - return { 'vlans_count': vlans_count, 'vlans_table': vlans_table, - 'permissions': permissions, } @@ -954,11 +910,6 @@ class FHRPGroupView(generic.ObjectView): queryset = FHRPGroup.objects.all() def get_extra_context(self, request, instance): - # Get assigned IP addresses - ipaddress_table = tables.AssignedIPAddressesTable( - data=instance.ip_addresses.restrict(request.user, 'view'), - orderable=False - ) # Get assigned interfaces members_table = tables.FHRPGroupAssignmentTable( @@ -968,7 +919,6 @@ class FHRPGroupView(generic.ObjectView): members_table.columns.hide('group') return { - 'ipaddress_table': ipaddress_table, 'members_table': members_table, 'member_count': FHRPGroupAssignment.objects.filter(group=instance).count(), } diff --git a/netbox/templates/dcim/interface.html b/netbox/templates/dcim/interface.html index f10e60490..0566a0109 100644 --- a/netbox/templates/dcim/interface.html +++ b/netbox/templates/dcim/interface.html @@ -344,13 +344,10 @@
IP Addresses
-
- {% if ipaddress_table.rows %} - {% render_table ipaddress_table 'inc/table.html' %} - {% else %} -
None
- {% endif %} -
+
{% if perms.ipam.add_ipaddress %}
diff --git a/netbox/templates/htmx/table.html b/netbox/templates/htmx/table.html index 6f168ac52..8d56a4427 100644 --- a/netbox/templates/htmx/table.html +++ b/netbox/templates/htmx/table.html @@ -4,10 +4,10 @@ {% with preferences|get_key:"pagination.placement" as paginator_placement %} {% if paginator_placement == 'top' or paginator_placement == 'both' %} - {% include 'inc/paginator_htmx.html' with paginator=table.paginator page=table.page %} + {% include 'inc/paginator_htmx.html' with table=table paginator=table.paginator page=table.page %} {% endif %} {% render_table table 'inc/table_htmx.html' %} {% if paginator_placement != 'top' %} - {% include 'inc/paginator_htmx.html' with paginator=table.paginator page=table.page %} + {% include 'inc/paginator_htmx.html' with table=table paginator=table.paginator page=table.page %} {% endif %} {% endwith %} diff --git a/netbox/templates/inc/paginator_htmx.html b/netbox/templates/inc/paginator_htmx.html index c580bd9fc..5b9eab7b1 100644 --- a/netbox/templates/inc/paginator_htmx.html +++ b/netbox/templates/inc/paginator_htmx.html @@ -7,9 +7,9 @@
{% if page.has_previous %} @@ -18,9 +18,9 @@ {% for p in page.smart_pages %} {% if p %} {{ p }} @@ -33,9 +33,9 @@ {% endfor %} {% if page.has_next %} @@ -55,9 +55,9 @@ {% for n in page.paginator.get_page_lengths %}
  • {{ n }}
  • diff --git a/netbox/templates/ipam/asn.html b/netbox/templates/ipam/asn.html index 3af5177cc..26903b71c 100644 --- a/netbox/templates/ipam/asn.html +++ b/netbox/templates/ipam/asn.html @@ -75,17 +75,17 @@
    Sites
    -
    - {% render_table sites_table 'inc/table.html' %} - {% include 'inc/paginator.html' with paginator=sites_table.paginator page=sites_table.page %} -
    +
    Providers
    -
    - {% render_table providers_table 'inc/table.html' %} - {% include 'inc/paginator.html' with paginator=providers_table.paginator page=providers_table.page %} -
    +
    {% plugin_full_width_page object %}
    diff --git a/netbox/templates/ipam/fhrpgroup.html b/netbox/templates/ipam/fhrpgroup.html index a74ddac70..6a43f9eca 100644 --- a/netbox/templates/ipam/fhrpgroup.html +++ b/netbox/templates/ipam/fhrpgroup.html @@ -69,13 +69,10 @@
    - {% include 'inc/panels/tags.html' %} {% plugin_left_page object %}
    + {% include 'inc/panels/tags.html' %} {% include 'inc/panels/custom_fields.html' %} {% plugin_right_page object %}
    @@ -53,10 +53,10 @@
    Aggregates
    -
    - {% render_table aggregates_table 'inc/table.html' %} - {% include 'inc/paginator.html' with paginator=aggregates_table.paginator page=aggregates_table.page %} -
    +
    {% plugin_full_width_page object %}
    diff --git a/netbox/templates/ipam/role.html b/netbox/templates/ipam/role.html index a6ef2c6d4..1018824e9 100644 --- a/netbox/templates/ipam/role.html +++ b/netbox/templates/ipam/role.html @@ -35,40 +35,28 @@ Prefixes - {{ prefixes_table.rows|length }} + {{ object.prefixes.count }} IP Ranges - {% with ipranges_count=object.ip_ranges.count %} - {% if ipranges_count %} - {{ ipranges_count }} - {% else %} - {{ ''|placeholder }} - {% endif %} - {% endwith %} + {{ object.ip_ranges.count }} VLANs - {% with vlans_count=object.vlans.count %} - {% if vlans_count %} - {{ vlans_count }} - {% else %} - {{ ''|placeholder }} - {% endif %} - {% endwith %} + {{ object.vlans.count }}
    - {% include 'inc/panels/tags.html' %} {% plugin_left_page object %}
    + {% include 'inc/panels/tags.html' %} {% include 'inc/panels/custom_fields.html' %} {% plugin_right_page object %}
    @@ -77,10 +65,10 @@
    Prefixes
    -
    - {% render_table prefixes_table 'inc/table.html' %} - {% include 'inc/paginator.html' with paginator=prefixes_table.paginator page=prefixes_table.page %} -
    +
    {% plugin_full_width_page object %}
    diff --git a/netbox/templates/ipam/vlan.html b/netbox/templates/ipam/vlan.html index c0f68bae2..4dcd2318a 100644 --- a/netbox/templates/ipam/vlan.html +++ b/netbox/templates/ipam/vlan.html @@ -81,24 +81,22 @@
    -
    -
    -
    - Prefixes -
    -
    - {% render_table prefix_table 'inc/table.html' %} -
    - {% if perms.ipam.add_prefix %} - - {% endif %} +
    +
    +
    Prefixes
    +
    + {% if perms.ipam.add_prefix %} + - {% plugin_full_width_page object %} + {% endif %}
    + {% plugin_full_width_page object %} +
    {% endblock %} diff --git a/netbox/templates/virtualization/clustergroup.html b/netbox/templates/virtualization/clustergroup.html index 1da700caf..7d7d5a677 100644 --- a/netbox/templates/virtualization/clustergroup.html +++ b/netbox/templates/virtualization/clustergroup.html @@ -31,7 +31,7 @@ Clusters - {{ clusters_table.rows|length }} + {{ object.clusters.count }} @@ -50,10 +50,10 @@
    Clusters
    -
    - {% render_table clusters_table 'inc/table.html' %} - {% include 'inc/paginator.html' with paginator=clusters_table.paginator page=clusters_table.page %} -
    +
    {% plugin_full_width_page object %}
    diff --git a/netbox/templates/virtualization/clustertype.html b/netbox/templates/virtualization/clustertype.html index e0ddc90e0..5a5379160 100644 --- a/netbox/templates/virtualization/clustertype.html +++ b/netbox/templates/virtualization/clustertype.html @@ -31,7 +31,7 @@ Clusters - {{ clusters_table.rows|length }} + {{ object.clusters.count }} @@ -49,10 +49,10 @@
    Clusters
    -
    - {% render_table clusters_table 'inc/table.html' %} - {% include 'inc/paginator.html' with paginator=clusters_table.paginator page=clusters_table.page %} -
    +
    {% plugin_full_width_page object %}
    diff --git a/netbox/templates/virtualization/vminterface.html b/netbox/templates/virtualization/vminterface.html index 635654f86..a7d4d92ba 100644 --- a/netbox/templates/virtualization/vminterface.html +++ b/netbox/templates/virtualization/vminterface.html @@ -80,16 +80,11 @@
    - {% include 'inc/panels/tags.html' %} {% plugin_left_page object %}
    + {% include 'inc/panels/tags.html' %} {% include 'inc/panels/custom_fields.html' %} {% plugin_right_page object %}
    @@ -57,11 +57,11 @@
    -
    Wireless LANs
    -
    - {% render_table wirelesslans_table 'inc/table.html' %} - {% include 'inc/paginator.html' with paginator=wirelesslans_table.paginator page=wirelesslans_table.page %} -
    +
    Wireless LANs
    +
    {% plugin_full_width_page object %}
    diff --git a/netbox/virtualization/views.py b/netbox/virtualization/views.py index af130fcce..bbb46face 100644 --- a/netbox/virtualization/views.py +++ b/netbox/virtualization/views.py @@ -100,20 +100,6 @@ class ClusterGroupListView(generic.ObjectListView): class ClusterGroupView(generic.ObjectView): queryset = ClusterGroup.objects.all() - def get_extra_context(self, request, instance): - clusters = Cluster.objects.restrict(request.user, 'view').filter( - group=instance - ).annotate( - device_count=count_related(Device, 'cluster'), - vm_count=count_related(VirtualMachine, 'cluster') - ) - clusters_table = tables.ClusterTable(clusters, user=request.user, exclude=('group',)) - clusters_table.configure(request) - - return { - 'clusters_table': clusters_table, - } - @register_model_view(ClusterGroup, 'edit') class ClusterGroupEditView(generic.ObjectEditView): @@ -444,11 +430,6 @@ class VMInterfaceView(generic.ObjectView): queryset = VMInterface.objects.all() def get_extra_context(self, request, instance): - # Get assigned IP addresses - ipaddress_table = AssignedIPAddressesTable( - data=instance.ip_addresses.restrict(request.user, 'view'), - orderable=False - ) # Get child interfaces child_interfaces = VMInterface.objects.restrict(request.user, 'view').filter(parent=instance) @@ -473,7 +454,6 @@ class VMInterfaceView(generic.ObjectView): ) return { - 'ipaddress_table': ipaddress_table, 'child_interfaces_table': child_interfaces_tables, 'vlan_table': vlan_table, } diff --git a/netbox/wireless/views.py b/netbox/wireless/views.py index 0e164cb1e..8665ed988 100644 --- a/netbox/wireless/views.py +++ b/netbox/wireless/views.py @@ -27,17 +27,6 @@ class WirelessLANGroupListView(generic.ObjectListView): class WirelessLANGroupView(generic.ObjectView): queryset = WirelessLANGroup.objects.all() - def get_extra_context(self, request, instance): - wirelesslans = WirelessLAN.objects.restrict(request.user, 'view').filter( - group=instance - ) - wirelesslans_table = tables.WirelessLANTable(wirelesslans, user=request.user, exclude=('group',)) - wirelesslans_table.configure(request) - - return { - 'wirelesslans_table': wirelesslans_table, - } - @register_model_view(WirelessLANGroup, 'edit') class WirelessLANGroupEditView(generic.ObjectEditView):