Merge pull request #5208 from glennmatthews/gfm-issue-5197

5197: Limit main IPAddress view to a max of 10 duplicate addresses; add new duplicates view
This commit is contained in:
Jeremy Stretch 2020-10-02 14:16:32 -04:00 committed by GitHub
commit cd9c425d9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -527,7 +527,8 @@ class IPAddressView(ObjectView):
# Exclude anycast IPs if this IP is anycast # Exclude anycast IPs if this IP is anycast
if ipaddress.role == IPAddressRoleChoices.ROLE_ANYCAST: if ipaddress.role == IPAddressRoleChoices.ROLE_ANYCAST:
duplicate_ips = duplicate_ips.exclude(role=IPAddressRoleChoices.ROLE_ANYCAST) duplicate_ips = duplicate_ips.exclude(role=IPAddressRoleChoices.ROLE_ANYCAST)
duplicate_ips_table = tables.IPAddressTable(list(duplicate_ips), orderable=False) # Limit to a maximum of 10 duplicates displayed here
duplicate_ips_table = tables.IPAddressTable(duplicate_ips[:10], orderable=False)
# Related IP table # Related IP table
related_ips = IPAddress.objects.restrict(request.user, 'view').exclude( related_ips = IPAddress.objects.restrict(request.user, 'view').exclude(
@ -547,6 +548,7 @@ class IPAddressView(ObjectView):
'ipaddress': ipaddress, 'ipaddress': ipaddress,
'parent_prefixes_table': parent_prefixes_table, 'parent_prefixes_table': parent_prefixes_table,
'duplicate_ips_table': duplicate_ips_table, 'duplicate_ips_table': duplicate_ips_table,
'more_duplicate_ips': duplicate_ips.count() > 10,
'related_ips_table': related_ips_table, 'related_ips_table': related_ips_table,
}) })

View File

@ -3,6 +3,7 @@
{% load custom_links %} {% load custom_links %}
{% load helpers %} {% load helpers %}
{% load plugins %} {% load plugins %}
{% load render_table from django_tables2 %}
{% block header %} {% block header %}
<div class="row noprint"> <div class="row noprint">
@ -159,7 +160,24 @@
<div class="col-md-8"> <div class="col-md-8">
{% include 'panel_table.html' with table=parent_prefixes_table heading='Parent Prefixes' %} {% include 'panel_table.html' with table=parent_prefixes_table heading='Parent Prefixes' %}
{% if duplicate_ips_table.rows %} {% if duplicate_ips_table.rows %}
{% include 'panel_table.html' with table=duplicate_ips_table heading='Duplicate IP Addresses' panel_class='danger' %} {# Custom version of panel_table.html #}
<div class="panel panel-danger">
<div class="panel-heading">
<strong>Duplicate IP Addresses</strong>
{% if more_duplicate_ips %}
<div class="pull-right">
<a type="button" class="btn btn-primary btn-xs"
{% if ipaddress.vrf %}
href="{% url 'ipam:ipaddress_list' %}?address={{ ipaddress.address.ip }}&vrf_id={{ ipaddress.vrf.pk }}"
{% else %}
href="{% url 'ipam:ipaddress_list' %}?address={{ ipaddress.address.ip }}&vrf_id=null"
{% endif %}
>Show all</a>
</div>
{% endif %}
</div>
{% render_table duplicate_ips_table 'inc/table.html' %}
</div>
{% endif %} {% endif %}
{% include 'utilities/obj_table.html' with table=related_ips_table table_template='panel_table.html' heading='Related IP Addresses' panel_class='default noprint' %} {% include 'utilities/obj_table.html' with table=related_ips_table table_template='panel_table.html' heading='Related IP Addresses' panel_class='default noprint' %}
{% plugin_right_page ipaddress %} {% plugin_right_page ipaddress %}