diff --git a/netbox/ipam/tables/template_code.py b/netbox/ipam/tables/template_code.py index 0182ba7de..cc3a344bc 100644 --- a/netbox/ipam/tables/template_code.py +++ b/netbox/ipam/tables/template_code.py @@ -26,14 +26,12 @@ PREFIX_LINK_WITH_DEPTH = """ """ + PREFIX_LINK IPADDRESS_LINK = """ -{% if record.address %} - {{ record.address }} -{% elif record.start_address %} - {{ record }} +{% if record.address or record.start_address %} + {{ record }} {% elif perms.ipam.add_ipaddress %} - {% if record.size <= 65536 %}{{ record.size }}{% else %}Many{% endif %} IP{{ record.size|pluralize }} available + {{ record.title }} {% else %} - {% if record.size <= 65536 %}{{ record.size }}{% else %}Many{% endif %} IP{{ record.size|pluralize }} available + {{ record.title }} {% endif %} """ diff --git a/netbox/ipam/utils.py b/netbox/ipam/utils.py index 13d0680d6..8fe40592e 100644 --- a/netbox/ipam/utils.py +++ b/netbox/ipam/utils.py @@ -1,6 +1,8 @@ from dataclasses import dataclass import netaddr +from django.utils.translation import gettext_lazy as _ + from .constants import * from .models import Prefix, VLAN @@ -16,9 +18,20 @@ __all__ = ( @dataclass class AvailableIPSpace: + """ + A representation of available IP space between two IP addresses/ranges. + """ size: int first_ip: str + @property + def title(self): + if self.size == 1: + return _('1 IP available') + if self.size <= 65536: + return _('{count} IPs available').format(count=self.size) + return _('Many IPs available') + def add_requested_prefixes(parent, prefix_list, show_available=True, show_assigned=True): """