1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #7665 add new boolen for filtering assigned prefixes, adjust current filter for avaliabile prefixes to only return avaliable

This commit is contained in:
Will Irvine
2021-11-13 13:27:49 +13:00
parent 8f1acb700d
commit 0edf9b17f6
3 changed files with 27 additions and 10 deletions

View File

@ -13,12 +13,7 @@ def add_available_prefixes(parent, prefix_list):
available_prefixes = netaddr.IPSet(parent) ^ netaddr.IPSet([p.prefix for p in prefix_list])
available_prefixes = [Prefix(prefix=p, status=None) for p in available_prefixes.iter_cidrs()]
# Concatenate and sort complete list of children
prefix_list = list(prefix_list) + available_prefixes
prefix_list.sort(key=lambda p: p.prefix)
return prefix_list
return available_prefixes
def add_available_ipaddresses(prefix, ipaddress_list, is_pool=False):
"""

View File

@ -393,14 +393,24 @@ class PrefixPrefixesView(generic.ObjectView):
template_name = 'ipam/prefix/prefixes.html'
def get_extra_context(self, request, instance):
# Child prefixes table
child_prefixes = instance.get_child_prefixes().restrict(request.user, 'view').prefetch_related(
# Initial pull of currently assigned child prefixes
child_prefixes_assigned = instance.get_child_prefixes().restrict(request.user, 'view').prefetch_related(
'site', 'vlan', 'role',
)
# List to append filtered prefixes to
child_prefixes = []
# Add available prefixes to the table if requested
if child_prefixes and request.GET.get('show_available', 'true') == 'true':
child_prefixes = add_available_prefixes(instance.prefix, child_prefixes)
if child_prefixes_assigned and request.GET.get('show_available', 'true') == 'true':
child_prefixes = child_prefixes + add_available_prefixes(instance.prefix, child_prefixes_assigned)
# Add assigned prefixes to the table if requested
if child_prefixes_assigned and request.GET.get('show_assigned', 'true') == 'true':
child_prefixes = child_prefixes + list(child_prefixes_assigned)
# Sort child prefixes after additions
child_prefixes.sort(key=lambda p: p.prefix)
table = tables.PrefixTable(child_prefixes, user=request.user, exclude=('utilization',))
if request.user.has_perm('ipam.change_prefix') or request.user.has_perm('ipam.delete_prefix'):
@ -422,6 +432,7 @@ class PrefixPrefixesView(generic.ObjectView):
'active_tab': 'prefixes',
'first_available_prefix': instance.get_first_available_prefix(),
'show_available': request.GET.get('show_available', 'true') == 'true',
'show_assigned': request.GET.get('show_assigned', 'true') == 'true',
}

View File

@ -1,5 +1,16 @@
{% load helpers %}
{% if show_assigned is not None %}
<div class="btn-group" role="group">
<a href="{{ request.path }}{% querystring request show_assigned='true' %}" class="btn btn-sm btn-outline-primary{% if show_assigned %} active disabled{% endif %}">
<i class="mdi mdi-eye"></i> Show Assigned
</a>
<a href="{{ request.path }}{% querystring request show_assigned='false' %}" class="btn btn-sm btn-outline-primary{% if not show_assigned %} active disabled{% endif %}">
<i class="mdi mdi-eye-off"></i> Hide Assigned
</a>
</div>
{% endif %}
{% if show_available is not None %}
<div class="btn-group" role="group">
<a href="{{ request.path }}{% querystring request show_available='true' %}" class="btn btn-sm btn-outline-primary{% if show_available %} active disabled{% endif %}">