mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
#7665: Refactored add_requested_prefixes(); removed button icons
This commit is contained in:
@ -4,16 +4,20 @@ from .constants import *
|
||||
from .models import Prefix, VLAN
|
||||
|
||||
|
||||
def add_requested_prefixes(parent, prefix_list, request):
|
||||
"""
|
||||
Return a list of requested prefixes using show_available, show_assigned filters.
|
||||
If avalible prefixes are requested, create fake Prefix objects for all unallocated space within a prefix
|
||||
def add_requested_prefixes(parent, prefix_list, show_available=True, show_assigned=True):
|
||||
"""
|
||||
Return a list of requested prefixes using show_available, show_assigned filters. If available prefixes are
|
||||
requested, create fake Prefix objects for all unallocated space within a prefix.
|
||||
|
||||
:param parent: Parent Prefix instance
|
||||
:param prefix_list: Child prefixes list
|
||||
:param show_available: Include available prefixes.
|
||||
:param show_assigned: Show assigned prefixes.
|
||||
"""
|
||||
child_prefixes = []
|
||||
|
||||
# Add available prefixes to the table if requested
|
||||
if prefix_list and request.GET.get('show_available', 'true') == 'true':
|
||||
if prefix_list and show_available:
|
||||
|
||||
# Find all unallocated space, add fake Prefix objects to child_prefixes.
|
||||
available_prefixes = netaddr.IPSet(parent) ^ netaddr.IPSet([p.prefix for p in prefix_list])
|
||||
@ -21,7 +25,7 @@ def add_requested_prefixes(parent, prefix_list, request):
|
||||
child_prefixes = child_prefixes + available_prefixes
|
||||
|
||||
# Add assigned prefixes to the table if requested
|
||||
if prefix_list and request.GET.get('show_assigned', 'true') == 'true':
|
||||
if prefix_list and show_assigned:
|
||||
child_prefixes = child_prefixes + list(prefix_list)
|
||||
|
||||
# Sort child prefixes after additions
|
||||
|
@ -285,7 +285,9 @@ class AggregateView(generic.ObjectView):
|
||||
)
|
||||
|
||||
# Return List of requested Prefixes
|
||||
child_prefixes = add_requested_prefixes(instance.prefix, prefix_list, request)
|
||||
show_available = bool(request.GET.get('show_available', 'true') == 'true')
|
||||
show_assigned = bool(request.GET.get('show_assigned', 'true') == 'true')
|
||||
child_prefixes = add_requested_prefixes(instance.prefix, prefix_list, show_available, show_assigned)
|
||||
|
||||
prefix_table = tables.PrefixTable(child_prefixes, exclude=('utilization',))
|
||||
if request.user.has_perm('ipam.change_prefix') or request.user.has_perm('ipam.delete_prefix'):
|
||||
@ -303,8 +305,8 @@ class AggregateView(generic.ObjectView):
|
||||
'prefix_table': prefix_table,
|
||||
'permissions': permissions,
|
||||
'bulk_querystring': f'within={instance.prefix}',
|
||||
'show_available': request.GET.get('show_available', 'true') == 'true',
|
||||
'show_assigned': request.GET.get('show_assigned', 'true') == 'true',
|
||||
'show_available': show_available,
|
||||
'show_assigned': show_assigned,
|
||||
}
|
||||
|
||||
|
||||
@ -462,7 +464,9 @@ class PrefixPrefixesView(generic.ObjectView):
|
||||
)
|
||||
|
||||
# Return List of requested Prefixes
|
||||
child_prefixes = add_requested_prefixes(instance.prefix, prefix_list, request)
|
||||
show_available = bool(request.GET.get('show_available', 'true') == 'true')
|
||||
show_assigned = bool(request.GET.get('show_assigned', 'true') == 'true')
|
||||
child_prefixes = add_requested_prefixes(instance.prefix, prefix_list, show_available, show_assigned)
|
||||
|
||||
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'):
|
||||
@ -483,8 +487,8 @@ class PrefixPrefixesView(generic.ObjectView):
|
||||
'bulk_querystring': bulk_querystring,
|
||||
'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',
|
||||
'show_available': show_available,
|
||||
'show_assigned': show_assigned,
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,14 +2,14 @@
|
||||
|
||||
{% if show_assigned or show_available is not None %}
|
||||
<div class="btn-group" role="group">
|
||||
<a href="{{ request.path }}{% querystring request show_assigned='true' show_available='false' %}" class="btn btn-sm btn-outline-primary{% if show_assigned and not show_available %} active disabled{% endif %}">
|
||||
<i class="mdi mdi-eye-outline"></i> Show Assigned
|
||||
<a href="{{ request.path }}{% querystring request show_assigned='true' show_available='false' %}" class="btn btn-sm {% if show_assigned and not show_available %}btn-primary active{% else %}btn-outline-primary{% endif %}">
|
||||
Show Assigned
|
||||
</a>
|
||||
<a href="{{ request.path }}{% querystring request show_assigned='false' show_available='true' %}" class="btn btn-sm btn-outline-primary{% if show_available and not show_assigned %} active disabled{% endif %}">
|
||||
<i class="mdi mdi-eye"></i> Show Available
|
||||
<a href="{{ request.path }}{% querystring request show_assigned='false' show_available='true' %}" class="btn btn-sm {% if show_available and not show_assigned %}btn-primary active{% else %}btn-outline-primary{% endif %}">
|
||||
Show Available
|
||||
</a>
|
||||
<a href="{{ request.path }}{% querystring request show_assigned='true' show_available='true' %}" class="btn btn-sm btn-outline-primary{% if show_available and show_assigned %} active disabled{% endif %}">
|
||||
<i class="mdi mdi-eye-plus"></i> Show All
|
||||
<a href="{{ request.path }}{% querystring request show_assigned='true' show_available='true' %}" class="btn btn-sm {% if show_available and show_assigned %}btn-primary active{% else %}btn-outline-primary{% endif %}">
|
||||
Show All
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
Reference in New Issue
Block a user