mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Update prefix children views to use ObjectChildrenView
This commit is contained in:
@ -453,103 +453,60 @@ class PrefixView(generic.ObjectView):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class PrefixPrefixesView(generic.ObjectView):
|
class PrefixPrefixesView(generic.ObjectChildrenView):
|
||||||
queryset = Prefix.objects.all()
|
queryset = Prefix.objects.all()
|
||||||
|
child_model = Prefix
|
||||||
|
table = tables.PrefixTable
|
||||||
template_name = 'ipam/prefix/prefixes.html'
|
template_name = 'ipam/prefix/prefixes.html'
|
||||||
|
|
||||||
def get_extra_context(self, request, instance):
|
def get_children(self, request, parent):
|
||||||
# Find all child prefixes contained in this prefix
|
child_prefixes = parent.get_child_prefixes().restrict(request.user, 'view')
|
||||||
prefix_list = instance.get_child_prefixes().restrict(request.user, 'view').prefetch_related(
|
|
||||||
'site', 'vlan', 'role',
|
|
||||||
)
|
|
||||||
|
|
||||||
# Return List of requested Prefixes
|
# Add available prefixes if requested
|
||||||
show_available = bool(request.GET.get('show_available', 'true') == 'true')
|
show_available = bool(request.GET.get('show_available', 'true') == 'true')
|
||||||
show_assigned = bool(request.GET.get('show_assigned', '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)
|
child_prefixes = add_requested_prefixes(parent.prefix, child_prefixes, show_available, show_assigned)
|
||||||
|
|
||||||
table = tables.PrefixTable(child_prefixes, user=request.user, exclude=('utilization',))
|
return child_prefixes
|
||||||
if request.user.has_perm('ipam.change_prefix') or request.user.has_perm('ipam.delete_prefix'):
|
|
||||||
table.columns.show('pk')
|
|
||||||
paginate_table(table, request)
|
|
||||||
|
|
||||||
bulk_querystring = 'vrf_id={}&within={}'.format(instance.vrf.pk if instance.vrf else '0', instance.prefix)
|
|
||||||
|
|
||||||
# Compile permissions list for rendering the object table
|
|
||||||
permissions = {
|
|
||||||
'change': request.user.has_perm('ipam.change_prefix'),
|
|
||||||
'delete': request.user.has_perm('ipam.delete_prefix'),
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
'table': table,
|
|
||||||
'permissions': permissions,
|
|
||||||
'bulk_querystring': bulk_querystring,
|
|
||||||
'active_tab': 'prefixes',
|
|
||||||
'first_available_prefix': instance.get_first_available_prefix(),
|
|
||||||
'show_available': show_available,
|
|
||||||
'show_assigned': show_assigned,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class PrefixIPRangesView(generic.ObjectView):
|
|
||||||
queryset = Prefix.objects.all()
|
|
||||||
template_name = 'ipam/prefix/ip_ranges.html'
|
|
||||||
|
|
||||||
def get_extra_context(self, request, instance):
|
def get_extra_context(self, request, instance):
|
||||||
# Find all IPRanges belonging to this Prefix
|
return {
|
||||||
ip_ranges = instance.get_child_ranges().restrict(request.user, 'view').prefetch_related('vrf')
|
'bulk_querystring': f"vrf_id={instance.vrf.pk if instance.vrf else '0'}&within={instance.prefix}",
|
||||||
|
'active_tab': 'prefixes',
|
||||||
table = tables.IPRangeTable(ip_ranges, user=request.user)
|
'first_available_prefix': instance.get_first_available_prefix(),
|
||||||
if request.user.has_perm('ipam.change_iprange') or request.user.has_perm('ipam.delete_iprange'):
|
'show_available': bool(request.GET.get('show_available', 'true') == 'true'),
|
||||||
table.columns.show('pk')
|
'show_assigned': bool(request.GET.get('show_assigned', 'true') == 'true'),
|
||||||
paginate_table(table, request)
|
|
||||||
|
|
||||||
bulk_querystring = 'vrf_id={}&parent={}'.format(instance.vrf.pk if instance.vrf else '0', instance.prefix)
|
|
||||||
|
|
||||||
# Compile permissions list for rendering the object table
|
|
||||||
permissions = {
|
|
||||||
'change': request.user.has_perm('ipam.change_iprange'),
|
|
||||||
'delete': request.user.has_perm('ipam.delete_iprange'),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class PrefixIPRangesView(generic.ObjectChildrenView):
|
||||||
|
queryset = Prefix.objects.all()
|
||||||
|
child_model = IPRange
|
||||||
|
table = tables.IPRangeTable
|
||||||
|
template_name = 'ipam/prefix/ip_ranges.html'
|
||||||
|
|
||||||
|
def get_children(self, request, parent):
|
||||||
|
return parent.get_child_ranges().restrict(request.user, 'view')
|
||||||
|
|
||||||
|
def get_extra_context(self, request, instance):
|
||||||
return {
|
return {
|
||||||
'table': table,
|
'bulk_querystring': f"vrf_id={instance.vrf.pk if instance.vrf else '0'}&parent={instance.prefix}",
|
||||||
'permissions': permissions,
|
|
||||||
'bulk_querystring': bulk_querystring,
|
|
||||||
'active_tab': 'ip-ranges',
|
'active_tab': 'ip-ranges',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class PrefixIPAddressesView(generic.ObjectView):
|
class PrefixIPAddressesView(generic.ObjectChildrenView):
|
||||||
queryset = Prefix.objects.all()
|
queryset = Prefix.objects.all()
|
||||||
|
child_model = IPAddress
|
||||||
|
table = tables.IPAddressTable
|
||||||
template_name = 'ipam/prefix/ip_addresses.html'
|
template_name = 'ipam/prefix/ip_addresses.html'
|
||||||
|
|
||||||
|
def get_children(self, request, parent):
|
||||||
|
return parent.get_child_ips().restrict(request.user, 'view')
|
||||||
|
|
||||||
def get_extra_context(self, request, instance):
|
def get_extra_context(self, request, instance):
|
||||||
# Find all IPAddresses belonging to this Prefix
|
|
||||||
ipaddresses = instance.get_child_ips().restrict(request.user, 'view').prefetch_related('vrf')
|
|
||||||
|
|
||||||
# Add available IP addresses to the table if requested
|
|
||||||
if request.GET.get('show_available', 'true') == 'true':
|
|
||||||
ipaddresses = add_available_ipaddresses(instance.prefix, ipaddresses, instance.is_pool)
|
|
||||||
|
|
||||||
table = tables.IPAddressTable(ipaddresses, user=request.user)
|
|
||||||
if request.user.has_perm('ipam.change_ipaddress') or request.user.has_perm('ipam.delete_ipaddress'):
|
|
||||||
table.columns.show('pk')
|
|
||||||
paginate_table(table, request)
|
|
||||||
|
|
||||||
bulk_querystring = 'vrf_id={}&parent={}'.format(instance.vrf.pk if instance.vrf else '0', instance.prefix)
|
|
||||||
|
|
||||||
# Compile permissions list for rendering the object table
|
|
||||||
permissions = {
|
|
||||||
'change': request.user.has_perm('ipam.change_ipaddress'),
|
|
||||||
'delete': request.user.has_perm('ipam.delete_ipaddress'),
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'table': table,
|
'bulk_querystring': f"vrf_id={instance.vrf.pk if instance.vrf else '0'}&parent={instance.prefix}",
|
||||||
'permissions': permissions,
|
|
||||||
'bulk_querystring': bulk_querystring,
|
|
||||||
'active_tab': 'ip-addresses',
|
'active_tab': 'ip-addresses',
|
||||||
'first_available_ip': instance.get_first_available_ip(),
|
'first_available_ip': instance.get_first_available_ip(),
|
||||||
'show_available': request.GET.get('show_available', 'true') == 'true',
|
'show_available': request.GET.get('show_available', 'true') == 'true',
|
||||||
|
Reference in New Issue
Block a user