2
0
Эх сурвалжийг харах

Fixes #3393: Paginate circuits at the provider details view

Saria Hajjar 6 жил өмнө
parent
commit
883655ce71

+ 1 - 0
docs/release-notes/version-2.6.md

@@ -9,6 +9,7 @@
 * [#3090](https://github.com/netbox-community/netbox/issues/3090) - Add filter field for device interfaces
 * [#3187](https://github.com/netbox-community/netbox/issues/3187) - Add rack selection field to rack elevations
 * [#3440](https://github.com/netbox-community/netbox/issues/3440) - Add total length to cable trace
+* [#3393](https://github.com/netbox-community/netbox/issues/3393) - Paginate the circuits at the provider details view
 * [#3851](https://github.com/netbox-community/netbox/issues/3851) - Allow passing initial data to custom script forms
 
 ## Bug Fixes

+ 11 - 1
netbox/circuits/views.py

@@ -1,3 +1,4 @@
+from django.conf import settings
 from django.contrib import messages
 from django.contrib.auth.decorators import permission_required
 from django.contrib.auth.mixins import PermissionRequiredMixin
@@ -5,9 +6,11 @@ from django.db import transaction
 from django.db.models import Count, OuterRef, Subquery
 from django.shortcuts import get_object_or_404, redirect, render
 from django.views.generic import View
+from django_tables2 import RequestConfig
 
 from extras.models import Graph, GRAPH_TYPE_PROVIDER
 from utilities.forms import ConfirmationForm
+from utilities.paginator import EnhancedPaginator
 from utilities.views import (
     BulkDeleteView, BulkEditView, BulkImportView, ObjectDeleteView, ObjectEditView, ObjectListView,
 )
@@ -36,11 +39,18 @@ class ProviderView(PermissionRequiredMixin, View):
 
         provider = get_object_or_404(Provider, slug=slug)
         circuits = Circuit.objects.filter(provider=provider).prefetch_related('type', 'tenant', 'terminations__site')
+        circuits_table = tables.CircuitTable(circuits, orderable=False)
         show_graphs = Graph.objects.filter(type=GRAPH_TYPE_PROVIDER).exists()
 
+        paginate = {
+            'paginator_class': EnhancedPaginator,
+            'per_page': request.GET.get('per_page', settings.PAGINATE_COUNT)
+        }
+        RequestConfig(request, paginate).configure(circuits_table)
+
         return render(request, 'circuits/provider.html', {
             'provider': provider,
-            'circuits': circuits,
+            'circuits_table': circuits_table,
             'show_graphs': show_graphs,
         })
 

+ 2 - 52
netbox/templates/circuits/provider.html

@@ -125,58 +125,7 @@
             <div class="panel-heading">
                 <strong>Circuits</strong>
             </div>
-            <table class="table table-hover panel-body">
-                <tr>
-                    <th>Circuit ID</th>
-                    <th>Type</th>
-                    <th>Tenant</th>
-                    <th>A Side</th>
-                    <th>Z Side</th>
-                    <th>Description</th>
-                </tr>
-                {% for c in circuits %}
-                    <tr>
-                        <td>
-                            <a href="{% url 'circuits:circuit' pk=c.pk %}">{{ c.cid }}</a>
-                        </td>
-                        <td>
-                            <a href="{% url 'circuits:circuit_list' %}?type={{ c.type.slug }}">{{ c.type }}</a>
-                        </td>
-                        <td>
-                            {% if c.tenant %}
-                                <a href="{% url 'tenancy:tenant' slug=c.tenant.slug %}">{{ c.tenant }}</a>
-                            {% else %}
-                                <span class="text-muted">&mdash;</span>
-                            {% endif %}
-                        </td>
-                        <td>
-                            {% if c.termination_a %}
-                                <a href="{% url 'dcim:site' slug=c.termination_a.site.slug %}">{{ c.termination_a.site }}</a>
-                            {% else %}
-                                <span class="text-muted">&mdash;</span>
-                            {% endif %}
-                        </td>
-                        <td>
-                            {% if c.termination_z %}
-                                <a href="{% url 'dcim:site' slug=c.termination_z.site.slug %}">{{ c.termination_z.site }}</a>
-                            {% else %}
-                                <span class="text-muted">&mdash;</span>
-                            {% endif %}
-                        </td>
-                        <td>
-                            {% if c.description %}
-                                {{ c.description }}
-                            {% else %}
-                                <span class="text-muted">&mdash;</span>
-                            {% endif %}
-                        </td>
-                    </tr>
-                {% empty %}
-                    <tr>
-                        <td colspan="6" class="text-muted">None</td>
-                    </tr>
-                {% endfor %}
-            </table>
+            {% include 'inc/table.html' with table=circuits_table %}
             {% if perms.circuits.add_circuit %}
                 <div class="panel-footer text-right noprint">
                     <a href="{% url 'circuits:circuit_add' %}?provider={{ provider.pk }}" class="btn btn-xs btn-primary">
@@ -185,6 +134,7 @@
                 </div>
             {% endif %}
         </div>
+    {% include 'inc/paginator.html' with paginator=circuits_table.paginator page=circuits_table.page %}
     </div>
 </div>
 {% include 'inc/modal.html' with modal_name='graphs' %}