Formatting for nameservers

This commit is contained in:
Rebecca Hsieh 2023-10-20 14:42:33 -07:00
parent 1644109292
commit 18447c1486
No known key found for this signature in database
GPG key ID: 644527A2F375A379
2 changed files with 40 additions and 2 deletions

View file

@ -2,6 +2,7 @@ from itertools import zip_longest
import logging import logging
import ipaddress import ipaddress
import re import re
import string
from datetime import date from datetime import date
from string import digits from string import digits
from typing import Optional from typing import Optional
@ -228,6 +229,43 @@ class Domain(TimeStampedModel, DomainHelper):
""" """
raise NotImplementedError() raise NotImplementedError()
@Cache
def format_nameservers(self):
"""
Formatting nameservers for display for this domain.
Hosts are provided as a list of tuples, e.g.
[("ns1.example.com",), ("ns1.example.gov", ["0.0.0.0"])]
We want to display as:
ns1.example.gov
ns1.example.gov (0.0.0.0)
Subordinate hosts (something.your-domain.gov) MUST have IP addresses,
while non-subordinate hosts MUST NOT.
"""
try:
hosts = self._get_property("hosts")
except Exception as err:
# Do not raise error when missing nameservers
# this is a standard occurence when a domain
# is first created
logger.info("Domain is missing nameservers %s" % err)
return []
hostList = []
for host in hosts:
host_info = host["name"]
if len(host["addrs"]) > 0:
converter = string.maketrans("[]", "()")
host_info.append(host["addrs"].translate(converter, "'"))
hostList.append(host_info)
return hostList
@Cache @Cache
def nameservers(self) -> list[tuple[str, list]]: def nameservers(self) -> list[tuple[str, list]]:
""" """

View file

@ -28,8 +28,8 @@
<br> <br>
{% url 'domain-dns-nameservers' pk=domain.id as url %} {% url 'domain-dns-nameservers' pk=domain.id as url %}
{% if domain.nameservers|length > 0 %} {% if domain.format_nameservers|length > 0 %}
{% include "includes/summary_item.html" with title='DNS name servers' value=domain.nameservers list='true' edit_link=url %} {% include "includes/summary_item.html" with title='DNS name servers' value=domain.format_nameservers list='true' edit_link=url %}
{% else %} {% else %}
<h2 class="margin-top-neg-1"> DNS name servers </h2> <h2 class="margin-top-neg-1"> DNS name servers </h2>
<p> No DNS name servers have been added yet. Before your domain can be used well need information about your domain name servers.</p> <p> No DNS name servers have been added yet. Before your domain can be used well need information about your domain name servers.</p>