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:
@@ -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',
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user