コード例 #1
0
ファイル: views.py プロジェクト: rollerd/django-dns
def html_name(request, name):
    """
    Displays the sorted by name data in html format. (NOTE: should combine this into one function with html_ ip)
    See html_ip above - info is the same, sort order is by hostname rather than IP
    """
    sortby = "name"
    subnet_info = Subnet.objects.get(subnet_name=name)
    proper_name = subnet_info.proper_name
    mapping = Mapping.objects.filter(subnet_id=name)
    ip_host_list = []
    cname_host_list = []
    for obj in mapping:
        if pylib.is_valid_ip(obj.ip_or_cname):
            ip_host_list.append((obj.ip_or_cname, obj.hostname))
        else:
            cname_host_list.append((obj.hostname, obj.ip_or_cname))
    total_ips = pylib.determine_total_num_ips(subnet_info.ip_range_start, subnet_info.ip_range_end)
    total_registered_ips = len(ip_host_list)
    available_ips = total_ips - total_registered_ips
    sorted_list = sorted(ip_host_list, key=lambda name: name[1])
    context = {
        "sorted_list": sorted_list,
        "cname_host_list": cname_host_list,
        "sortby": sortby,
        "subnet_name": name,
        "subnet_info": subnet_info,
        "total_ips": total_ips,
        "total_registered_ips": total_registered_ips,
        "available_ips": available_ips,
        "proper_name": proper_name,
    }
    return render(request, "pdns/html.html", context)
コード例 #2
0
ファイル: views.py プロジェクト: rollerd/django-dns
def html_ip(request, name):
    """
    Displays the sorted by IP data in html format. (NOTE: should combine this into one function with html_ name)
    Collects IPs and CNAMES from the model and sorts them
    Returns render with sorted_ip list, sorted_cname list, sort_by order, subnet name, subnet_info, total_ips,
    total_registered_ips, available_ips, proper name (This info is created in pylib.py and used in the header of the page to render)

    arguments:
        request: request object
        name: subnet name
    """
    sortby = "ip"
    subnet_info = Subnet.objects.get(subnet_name=name)
    proper_name = subnet_info.proper_name
    mapping = Mapping.objects.filter(subnet_id=name)
    ip_host_list = []
    cname_host_list = []
    for obj in mapping:
        if pylib.is_valid_ip(obj.ip_or_cname):
            ip_host_list.append((obj.ip_or_cname, obj.hostname))
        else:
            cname_host_list.append((obj.hostname, obj.ip_or_cname))
    total_ips = pylib.determine_total_num_ips(subnet_info.ip_range_start, subnet_info.ip_range_end)
    total_registered_ips = len(ip_host_list)
    available_ips = total_ips - total_registered_ips
    sorted_list = sorted(ip_host_list, key=lambda octet: socket.inet_aton(octet[0]))
    context = {
        "sorted_list": sorted_list,
        "cname_host_list": cname_host_list,
        "sortby": sortby,
        "subnet_name": name,
        "subnet_info": subnet_info,
        "total_ips": total_ips,
        "total_registered_ips": total_registered_ips,
        "available_ips": available_ips,
        "proper_name": proper_name,
    }
    return render(request, "pdns/html.html", context)