def range_detail(request, pk): mrange = get_object_or_404(Range, pk=pk) allow = None if mrange.allow == ALLOW_OPTION_VRF: try: allow = [Vrf.objects.get(network=mrange.network)] except ObjectDoesNotExist: allow = [] elif mrange.allow == ALLOW_OPTION_KNOWN: allow = [ALLOW_OPTION_KNOWN] elif mrange.allow == ALLOW_OPTION_LEGACY: allow = [ctnr for ctnr in Ctnr.objects.filter(ranges=mrange)] start_upper = mrange.start_upper start_lower = mrange.start_lower end_upper = mrange.end_upper end_lower = mrange.end_lower range_data, ip_usage_percent = range_usage( two_to_one(start_upper, start_lower), two_to_one(end_upper, end_lower), mrange.ip_type) return render(request, 'range/range_detail.html', { 'obj': mrange, 'obj_type': 'range', 'ranges_table': tablefy((mrange,)), 'range_data': make_paginator(request, range_data, 50), 'attrs_table': tablefy(mrange.rangekeyvalue_set.all()), 'allow_list': allow, 'range_used': "{0}%".format(ip_usage_percent) })
def range_detail(request, pk): mrange = get_object_or_404(Range, pk=pk) if mrange.allow == ALLOW_ANY: allow = ['Any client'] elif mrange.allow == ALLOW_KNOWN: allow = ['Known clients'] else: allow = [] if mrange.allow == ALLOW_VRF: allow += map(str, Vrf.objects.filter(network=mrange.network)) if mrange.allow == ALLOW_LEGACY: allow += map(str, Ctnr.objects.filter(ranges=mrange)) allow.sort(key=lambda x: x.lower()) range_type = mrange.range_type range_data = [] ip_usage_percent = None dynamic_interfaces = [] dynamic_interfaces_page_obj = None if range_type == 'st': start_upper = mrange.start_upper start_lower = mrange.start_lower end_upper = mrange.end_upper end_lower = mrange.end_lower range_data, ip_usage_percent = range_usage( two_to_one(start_upper, start_lower), two_to_one(end_upper, end_lower), mrange.ip_type) else: ip_usage_percent = mrange.range_usage DynamicInterface = get_model('cyder', 'dynamicinterface') dynamic_interfaces = DynamicInterface.objects.filter(range=mrange) dynamic_interfaces_page_obj = make_paginator( request, do_sort(request, dynamic_interfaces), 10) if ip_usage_percent: ip_usage_percent = "{0}%".format(ip_usage_percent) return render(request, 'range/range_detail.html', { 'obj': mrange, 'obj_type': 'range', 'pretty_obj_type': mrange.pretty_type, 'ranges_table': tablefy((mrange,), info=False, request=request), 'range_data': make_paginator(request, range_data, 50), 'range_type': range_type, 'attrs_table': tablefy(mrange.rangeav_set.all(), request=request), 'allow_list': allow, 'range_used': ip_usage_percent, 'dynamic_intr_table': tablefy(dynamic_interfaces_page_obj, info=True, request=request), 'page_obj': dynamic_interfaces_page_obj })