Skip to content

Commit

Permalink
Fixes netbox-community#1187: Fixed table pagination by introducing a …
Browse files Browse the repository at this point in the history
…custom table template
  • Loading branch information
jeremystretch committed May 16, 2017
1 parent 6257c7a commit 593f9d4
Show file tree
Hide file tree
Showing 42 changed files with 98 additions and 155 deletions.
4 changes: 2 additions & 2 deletions netbox/ipam/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
{% if record.pk %}
<a href="{{ record.get_absolute_url }}">{{ record.address }}</a>
{% elif perms.ipam.add_ipaddress %}
<a href="{% url 'ipam:ipaddress_add' %}?address={{ record.1 }}{% if prefix.vrf %}&vrf={{ prefix.vrf.pk }}{% endif %}" class="btn btn-xs btn-success">{% if record.0 <= 65536 %}{{ record.0 }}{% else %}Lots of{% endif %} free IP{{ record.0|pluralize }}</a>
<a href="{% url 'ipam:ipaddress_add' %}?address={{ record.1 }}{% if prefix.vrf %}&vrf={{ prefix.vrf.pk }}{% endif %}" class="btn btn-xs btn-success">{% if record.0 <= 65536 %}{{ record.0 }}{% else %}Many{% endif %} IP{{ record.0|pluralize }} available</a>
{% else %}
{{ record.0 }}
{% if record.0 <= 65536 %}{{ record.0 }}{% else %}Many{% endif %} IP{{ record.0|pluralize }} available
{% endif %}
"""

Expand Down
2 changes: 0 additions & 2 deletions netbox/templates/circuits/circuit_import.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{% extends 'utilities/obj_import.html' %}
{% load render_table from django_tables2 %}
{% load form_helpers %}

{% block title %}Circuit Import{% endblock %}

Expand Down
2 changes: 0 additions & 2 deletions netbox/templates/circuits/provider_import.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{% extends 'utilities/obj_import.html' %}
{% load render_table from django_tables2 %}
{% load form_helpers %}

{% block title %}Provider Import{% endblock %}

Expand Down
2 changes: 0 additions & 2 deletions netbox/templates/dcim/console_connections_import.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{% extends 'utilities/obj_import.html' %}
{% load render_table from django_tables2 %}
{% load form_helpers %}

{% block title %}Console Connections Import{% endblock %}

Expand Down
3 changes: 1 addition & 2 deletions netbox/templates/dcim/console_connections_list.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends '_base.html' %}
{% load render_table from django_tables2 %}

{% block title %}Console Connections{% endblock %}

Expand All @@ -16,7 +15,7 @@
<h1>Console Connections</h1>
<div class="row">
<div class="col-md-9">
{% render_table table 'table.html' %}
{% include 'responsive_table.html' %}
</div>
<div class="col-md-3">
{% include 'inc/search_panel.html' %}
Expand Down
1 change: 0 additions & 1 deletion netbox/templates/dcim/device.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% extends '_base.html' %}
{% load static from staticfiles %}
{% load render_table from django_tables2 %}
{% load helpers %}

{% block title %}{{ device }}{% endblock %}
Expand Down
1 change: 0 additions & 1 deletion netbox/templates/dcim/device_import.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends '_base.html' %}
{% load render_table from django_tables2 %}
{% load form_helpers %}

{% block title %}Device Import{% endblock %}
Expand Down
1 change: 0 additions & 1 deletion netbox/templates/dcim/device_import_child.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends '_base.html' %}
{% load render_table from django_tables2 %}
{% load form_helpers %}

{% block title %}Device Import{% endblock %}
Expand Down
1 change: 0 additions & 1 deletion netbox/templates/dcim/devicetype.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% extends '_base.html' %}
{% load helpers %}
{% load render_table from django_tables2 %}

{% block title %}{{ devicetype.manufacturer }} {{ devicetype.model }}{% endblock %}

Expand Down
5 changes: 2 additions & 3 deletions netbox/templates/dcim/inc/devicetype_component_table.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{% load render_table from django_tables2 %}
{% if perms.dcim.change_devicetype %}
<form method="post">
{% csrf_token %}
Expand All @@ -19,7 +18,7 @@
{% endif %}
</div>
</div>
{% render_table table 'table.html' %}
{% include 'responsive_table.html' %}
<div class="panel-footer">
{% if table.rows %}
{% if edit_url %}
Expand Down Expand Up @@ -48,6 +47,6 @@
<div class="panel-heading">
<strong>{{ title }}</strong>
</div>
{% render_table table 'table.html' %}
{% include 'responsive_table.html' %}
</div>
{% endif %}
2 changes: 0 additions & 2 deletions netbox/templates/dcim/interface_connections_import.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{% extends 'utilities/obj_import.html' %}
{% load render_table from django_tables2 %}
{% load form_helpers %}

{% block title %}Interface Connections Import{% endblock %}

Expand Down
3 changes: 1 addition & 2 deletions netbox/templates/dcim/interface_connections_list.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends '_base.html' %}
{% load render_table from django_tables2 %}

{% block title %}Interface Connections{% endblock %}

Expand All @@ -16,7 +15,7 @@
<h1>Interface Connections</h1>
<div class="row">
<div class="col-md-9">
{% render_table table 'table.html' %}
{% include 'responsive_table.html' %}
</div>
<div class="col-md-3">
{% include 'inc/search_panel.html' %}
Expand Down
2 changes: 0 additions & 2 deletions netbox/templates/dcim/power_connections_import.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{% extends 'utilities/obj_import.html' %}
{% load render_table from django_tables2 %}
{% load form_helpers %}

{% block title %}Power Connections Import{% endblock %}

Expand Down
3 changes: 1 addition & 2 deletions netbox/templates/dcim/power_connections_list.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends '_base.html' %}
{% load render_table from django_tables2 %}

{% block title %}Power Connections{% endblock %}

Expand All @@ -16,7 +15,7 @@
<h1>Power Connections</h1>
<div class="row">
<div class="col-md-9">
{% render_table table 'table.html' %}
{% include 'responsive_table.html' %}
</div>
<div class="col-md-3">
{% include 'inc/search_panel.html' %}
Expand Down
1 change: 0 additions & 1 deletion netbox/templates/dcim/rack.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% extends '_base.html' %}
{% load helpers %}
{% load render_table from django_tables2 %}

{% block title %}{{ rack.site }} - Rack {{ rack.name }}{% endblock %}

Expand Down
33 changes: 17 additions & 16 deletions netbox/templates/dcim/rack_elevation_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,25 @@ <h1>{% block title %}Rack Elevations{% endblock %}</h1>
{% if page %}
<div class="col-md-9">
<div style="white-space: nowrap; overflow-x: scroll;">
{% for rack in page %}
<div style="display: inline-block; width: 266px">
<div class="rack_header">
<h4><a href="{% url 'dcim:rack' pk=rack.pk %}">{{ rack.name }}</a></h4>
{% for rack in page %}
<div style="display: inline-block; width: 266px">
<div class="rack_header">
<h4><a href="{% url 'dcim:rack' pk=rack.pk %}">{{ rack.name }}</a></h4>
</div>
{% if face_id %}
{% include 'dcim/inc/rack_elevation.html' with primary_face=rack.get_rear_elevation secondary_face=rack.get_front_elevation face_id=1 %}
{% else %}
{% include 'dcim/inc/rack_elevation.html' with primary_face=rack.get_front_elevation secondary_face=rack.get_rear_elevation face_id=0 %}
{% endif %}
<div class="clearfix"></div>
<div class="rack_header">
<h4><a href="{% url 'dcim:rack' pk=rack.pk %}">{{ rack.name }}</a></h4>
</div>
</div>
{% if face_id %}
{% include 'dcim/inc/rack_elevation.html' with primary_face=rack.get_rear_elevation secondary_face=rack.get_front_elevation face_id=1 %}
{% else %}
{% include 'dcim/inc/rack_elevation.html' with primary_face=rack.get_front_elevation secondary_face=rack.get_rear_elevation face_id=0 %}
{% endif %}
<div class="clearfix"></div>
<div class="rack_header">
<h4><a href="{% url 'dcim:rack' pk=rack.pk %}">{{ rack.name }}</a></h4>
</div>
</div>
{% endfor %}
{% endfor %}
</div>
{% include 'paginator.html' %}
<br />
{% include 'inc/paginator.html' %}
</div>
{% else %}
<div class="col-md-9">
Expand Down
2 changes: 0 additions & 2 deletions netbox/templates/dcim/rack_import.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{% extends 'utilities/obj_import.html' %}
{% load render_table from django_tables2 %}
{% load form_helpers %}

{% block title %}Rack Import{% endblock %}

Expand Down
1 change: 0 additions & 1 deletion netbox/templates/dcim/site.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% extends '_base.html' %}
{% load static from staticfiles %}
{% load render_table from django_tables2 %}
{% load helpers %}

{% block title %}{{ site }}{% endblock %}
Expand Down
1 change: 0 additions & 1 deletion netbox/templates/dcim/site_import.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends '_base.html' %}
{% load render_table from django_tables2 %}
{% load form_helpers %}

{% block title %}Site Import{% endblock %}
Expand Down
1 change: 0 additions & 1 deletion netbox/templates/home.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends '_base.html' %}
{% load render_table from django_tables2 %}

{% block content %}
{% include 'search_form.html' %}
Expand Down
3 changes: 1 addition & 2 deletions netbox/templates/import_success.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{% extends '_base.html' %}
{% load render_table from django_tables2 %}

{% block content %}
<h1>{% block title %}Import Completed{% endblock %}</h1>
{% render_table table %}
{% include 'responsive_table.html' %}
<a href="{{ request.path }}" class="btn btn-primary">
<span class="fa fa-download" aria-hidden="true"></span>
Import more
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{% load helpers %}

<div class="paginator pull-right" style="margin-top: 20px">
<div class="paginator pull-right">
{% if paginator.num_pages > 1 %}
<nav>
<ul class="pagination pull-right">
{% if page.has_previous %}
<li><a href="{% querystring request page=page.previous_page_number %}">&laquo;</a></li>
<li><a href="{% querystring request page=page.previous_page_number %}"><i class="fa fa-angle-double-left"></i></a></li>
{% endif %}
{% for p in page.smart_pages %}
{% if p %}
Expand All @@ -15,13 +15,14 @@
{% endif %}
{% endfor %}
{% if page.has_next %}
<li><a href="{% querystring request page=page.next_page_number %}">&raquo;</a></li>
<li><a href="{% querystring request page=page.next_page_number %}"><i class="fa fa-angle-double-right"></i></a></li>
{% endif %}
</ul>
</nav>
{% endif %}
<div class="clearfix"></div>
<div class="text-right text-muted">
Showing {{ page.start_index }}-{{ page.end_index }} of {{ total_count }}
</div>
{% if page %}
<div class="text-right text-muted">
Showing {{ page.start_index }}-{{ page.end_index }} of {{ page.paginator.count }}
</div>
{% endif %}
</div>
41 changes: 41 additions & 0 deletions netbox/templates/inc/table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{% load django_tables2 %}

<table{% if table.attrs %} {{ table.attrs.as_html }}{% endif %}>
{% if table.show_header %}
<thead>
<tr>
{% for column in table.columns %}
{% if column.orderable %}
<th {{ column.attrs.th.as_html }}><a href="{% querystring page=column.order_by_alias.next %}">{{ column.header }}</a></th>
{% else %}
<th {{ column.attrs.th.as_html }}>{{ column.header }}</th>
{% endif %}
{% endfor %}
</tr>
</thead>
{% endif %}
<tbody>
{% for row in table.page.object_list|default:table.rows %}
<tr {{ row.attrs.as_html }}>
{% for column, cell in row.items %}
<td {{ column.attrs.td.as_html }}>{{ cell }}</td>
{% endfor %}
</tr>
{% empty %}
{% if table.empty_text %}
<tr>
<td colspan="{{ table.columns|length }}">{{ table.empty_text }}</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
{% if table.has_footer %}
<tfoot>
<tr>
{% for column in table.columns %}
<td>{{ column.footer }}</td>
{% endfor %}
</tr>
</tfoot>
{% endif %}
</table>
1 change: 0 additions & 1 deletion netbox/templates/ipam/aggregate.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends '_base.html' %}
{% load render_table from django_tables2 %}

{% block title %}Aggregate: {{ aggregate }}{% endblock %}

Expand Down
2 changes: 0 additions & 2 deletions netbox/templates/ipam/aggregate_import.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{% extends 'utilities/obj_import.html' %}
{% load render_table from django_tables2 %}
{% load form_helpers %}

{% block title %}Aggregate Import{% endblock %}

Expand Down
13 changes: 3 additions & 10 deletions netbox/templates/ipam/ipaddress.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends '_base.html' %}
{% load render_table from django_tables2 %}

{% block title %}{{ ipaddress }}{% endblock %}

Expand Down Expand Up @@ -133,17 +132,11 @@ <h1>{{ ipaddress }}</h1>
{% endwith %}
</div>
<div class="col-md-6">
{% with heading='Parent Prefixes' %}
{% render_table parent_prefixes_table 'panel_table.html' %}
{% endwith %}
{% include 'panel_table.html' with table=parent_prefixes_table heading='Parent Prefixes' %}
{% if duplicate_ips_table.rows %}
{% with heading='Duplicate IP Addresses' panel_class='danger' %}
{% render_table duplicate_ips_table 'panel_table.html' %}
{% endwith %}
{% include 'panel_table.html' with table=duplicate_ips_table heading='Duplicate IP Addresses' panel_class='danger' %}
{% endif %}
{% with heading='Related IP Addresses' %}
{% render_table related_ips_table 'panel_table.html' %}
{% endwith %}
{% include 'panel_table.html' with table=related_ips_table heading='Related IP Addresses' %}
</div>
</div>
{% endblock %}
2 changes: 0 additions & 2 deletions netbox/templates/ipam/ipaddress_import.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{% extends 'utilities/obj_import.html' %}
{% load render_table from django_tables2 %}
{% load form_helpers %}

{% block title %}IP Address Import{% endblock %}

Expand Down
9 changes: 2 additions & 7 deletions netbox/templates/ipam/prefix.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends '_base.html' %}
{% load render_table from django_tables2 %}

{% block title %}{{ prefix }}{% endblock %}

Expand Down Expand Up @@ -134,13 +133,9 @@
</div>
<div class="col-md-7">
{% if duplicate_prefix_table.rows %}
{% with heading='Duplicate Prefixes' panel_class='danger' %}
{% render_table duplicate_prefix_table 'panel_table.html' %}
{% endwith %}
{% include 'panel_table.html' with table=duplicate_prefix_table heading='Duplicate Prefixes' panel_class='danger' %}
{% endif %}
{% with heading='Parent Prefixes' %}
{% render_table parent_prefix_table 'panel_table.html' %}
{% endwith %}
{% include 'panel_table.html' with table=parent_prefix_table heading='Parent Prefixes' %}
</div>
</div>
<div class="row">
Expand Down
2 changes: 0 additions & 2 deletions netbox/templates/ipam/prefix_import.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{% extends 'utilities/obj_import.html' %}
{% load render_table from django_tables2 %}
{% load form_helpers %}

{% block title %}Prefix Import{% endblock %}

Expand Down
1 change: 0 additions & 1 deletion netbox/templates/ipam/prefix_ipaddresses.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends '_base.html' %}
{% load render_table from django_tables2 %}

{% block title %}{{ prefix }}{% endblock %}

Expand Down
3 changes: 1 addition & 2 deletions netbox/templates/ipam/vlan.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% extends '_base.html' %}
{% load render_table from django_tables2 %}

{% block title %}VLAN {{ vlan.display_name }}{% endblock %}

Expand Down Expand Up @@ -136,7 +135,7 @@ <h1>VLAN {{ vlan.display_name }}</h1>
<div class="panel-heading">
<strong>Prefixes</strong>
</div>
{% render_table prefix_table %}
{% include 'responsive_table.html' with table=prefix_table %}
{% if perms.ipam.add_prefix %}
<div class="panel-footer text-right">
<a href="{% url 'ipam:prefix_add' %}?{% if vlan.tenant %}tenant={{ vlan.tenant.pk }}&{% endif %}site={{ vlan.site.pk }}&vlan={{ vlan.pk }}" class="btn btn-primary btn-xs">
Expand Down
Loading

0 comments on commit 593f9d4

Please sign in to comment.