diff --git a/src/registrar/models/domain.py b/src/registrar/models/domain.py index c7d786426..ab0ad4b7b 100644 --- a/src/registrar/models/domain.py +++ b/src/registrar/models/domain.py @@ -2,6 +2,7 @@ from itertools import zip_longest import logging import ipaddress import re +import string from datetime import date from string import digits from typing import Optional @@ -228,6 +229,43 @@ class Domain(TimeStampedModel, DomainHelper): """ 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 def nameservers(self) -> list[tuple[str, list]]: """ diff --git a/src/registrar/templates/domain_detail.html b/src/registrar/templates/domain_detail.html index e0d672093..c5394e433 100644 --- a/src/registrar/templates/domain_detail.html +++ b/src/registrar/templates/domain_detail.html @@ -28,8 +28,8 @@
{% url 'domain-dns-nameservers' pk=domain.id as url %} - {% if domain.nameservers|length > 0 %} - {% include "includes/summary_item.html" with title='DNS name servers' value=domain.nameservers list='true' edit_link=url %} + {% if domain.format_nameservers|length > 0 %} + {% include "includes/summary_item.html" with title='DNS name servers' value=domain.format_nameservers list='true' edit_link=url %} {% else %}

DNS name servers

No DNS name servers have been added yet. Before your domain can be used we’ll need information about your domain name servers.