mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-20 02:06:42 -06: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:
parent
8f1acb700d
commit
0edf9b17f6
@ -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 = 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()]
|
available_prefixes = [Prefix(prefix=p, status=None) for p in available_prefixes.iter_cidrs()]
|
||||||
|
|
||||||
# Concatenate and sort complete list of children
|
return available_prefixes
|
||||||
prefix_list = list(prefix_list) + available_prefixes
|
|
||||||
prefix_list.sort(key=lambda p: p.prefix)
|
|
||||||
|
|
||||||
return prefix_list
|
|
||||||
|
|
||||||
|
|
||||||
def add_available_ipaddresses(prefix, ipaddress_list, is_pool=False):
|
def add_available_ipaddresses(prefix, ipaddress_list, is_pool=False):
|
||||||
"""
|
"""
|
||||||
|
@ -393,14 +393,24 @@ class PrefixPrefixesView(generic.ObjectView):
|
|||||||
template_name = 'ipam/prefix/prefixes.html'
|
template_name = 'ipam/prefix/prefixes.html'
|
||||||
|
|
||||||
def get_extra_context(self, request, instance):
|
def get_extra_context(self, request, instance):
|
||||||
# Child prefixes table
|
# Initial pull of currently assigned child prefixes
|
||||||
child_prefixes = instance.get_child_prefixes().restrict(request.user, 'view').prefetch_related(
|
child_prefixes_assigned = instance.get_child_prefixes().restrict(request.user, 'view').prefetch_related(
|
||||||
'site', 'vlan', 'role',
|
'site', 'vlan', 'role',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# List to append filtered prefixes to
|
||||||
|
child_prefixes = []
|
||||||
|
|
||||||
# Add available prefixes to the table if requested
|
# Add available prefixes to the table if requested
|
||||||
if child_prefixes and request.GET.get('show_available', 'true') == 'true':
|
if child_prefixes_assigned and request.GET.get('show_available', 'true') == 'true':
|
||||||
child_prefixes = add_available_prefixes(instance.prefix, child_prefixes)
|
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',))
|
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'):
|
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',
|
'active_tab': 'prefixes',
|
||||||
'first_available_prefix': instance.get_first_available_prefix(),
|
'first_available_prefix': instance.get_first_available_prefix(),
|
||||||
'show_available': request.GET.get('show_available', 'true') == 'true',
|
'show_available': request.GET.get('show_available', 'true') == 'true',
|
||||||
|
'show_assigned': request.GET.get('show_assigned', 'true') == 'true',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,16 @@
|
|||||||
{% load helpers %}
|
{% 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 %}
|
{% if show_available is not None %}
|
||||||
<div class="btn-group" role="group">
|
<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 %}">
|
<a href="{{ request.path }}{% querystring request show_available='true' %}" class="btn btn-sm btn-outline-primary{% if show_available %} active disabled{% endif %}">
|
||||||
|
Loading…
Reference in New Issue
Block a user