mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-02 05:46:25 -06:00
fixes #6895: some fields not exporting to CSV right
This commit is contained in:
parent
46d0af6cef
commit
0af55712c2
@ -21,14 +21,6 @@ PREFIX_LINK = """
|
|||||||
<a href="{% if record.pk %}{% url 'ipam:prefix' pk=record.pk %}{% else %}{% url 'ipam:prefix_add' %}?prefix={{ record }}{% if object.vrf %}&vrf={{ object.vrf.pk }}{% endif %}{% if object.site %}&site={{ object.site.pk }}{% endif %}{% if object.tenant %}&tenant_group={{ object.tenant.group.pk }}&tenant={{ object.tenant.pk }}{% endif %}{% endif %}">{{ record.prefix }}</a>
|
<a href="{% if record.pk %}{% url 'ipam:prefix' pk=record.pk %}{% else %}{% url 'ipam:prefix_add' %}?prefix={{ record }}{% if object.vrf %}&vrf={{ object.vrf.pk }}{% endif %}{% if object.site %}&site={{ object.site.pk }}{% endif %}{% if object.tenant %}&tenant_group={{ object.tenant.group.pk }}&tenant={{ object.tenant.pk }}{% endif %}{% endif %}">{{ record.prefix }}</a>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
PREFIX_ROLE_LINK = """
|
|
||||||
{% if record.role %}
|
|
||||||
<a href="{% url 'ipam:prefix_list' %}?role={{ record.role.slug }}">{{ record.role }}</a>
|
|
||||||
{% else %}
|
|
||||||
—
|
|
||||||
{% endif %}
|
|
||||||
"""
|
|
||||||
|
|
||||||
IPADDRESS_LINK = """
|
IPADDRESS_LINK = """
|
||||||
{% if record.pk %}
|
{% if record.pk %}
|
||||||
<a href="{{ record.get_absolute_url }}">{{ record.address }}</a>
|
<a href="{{ record.get_absolute_url }}">{{ record.address }}</a>
|
||||||
@ -53,14 +45,6 @@ VRF_LINK = """
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
VRF_TARGETS = """
|
|
||||||
{% for rt in value.all %}
|
|
||||||
<a href="{{ rt.get_absolute_url }}">{{ rt }}</a>{% if not forloop.last %}<br />{% endif %}
|
|
||||||
{% empty %}
|
|
||||||
—
|
|
||||||
{% endfor %}
|
|
||||||
"""
|
|
||||||
|
|
||||||
VLAN_LINK = """
|
VLAN_LINK = """
|
||||||
{% if record.pk %}
|
{% if record.pk %}
|
||||||
<a href="{{ record.get_absolute_url }}">{{ record.vid }}</a>
|
<a href="{{ record.get_absolute_url }}">{{ record.vid }}</a>
|
||||||
@ -71,14 +55,6 @@ VLAN_LINK = """
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
VLAN_PREFIXES = """
|
|
||||||
{% for prefix in record.prefixes.all %}
|
|
||||||
<a href="{% url 'ipam:prefix' pk=prefix.pk %}">{{ prefix }}</a>{% if not forloop.last %}<br />{% endif %}
|
|
||||||
{% empty %}
|
|
||||||
—
|
|
||||||
{% endfor %}
|
|
||||||
"""
|
|
||||||
|
|
||||||
VLAN_ROLE_LINK = """
|
VLAN_ROLE_LINK = """
|
||||||
{% if record.role %}
|
{% if record.role %}
|
||||||
<a href="{% url 'ipam:vlan_list' %}?role={{ record.role.slug }}">{{ record.role }}</a>
|
<a href="{% url 'ipam:vlan_list' %}?role={{ record.role.slug }}">{{ record.role }}</a>
|
||||||
@ -106,6 +82,42 @@ VLAN_MEMBER_TAGGED = """
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class PrefixColumn(tables.TemplateColumn):
|
||||||
|
|
||||||
|
template_code = """
|
||||||
|
{% for prefix in record.prefixes.all %}
|
||||||
|
<a href="{% url 'ipam:prefix' pk=prefix.pk %}">{{ prefix }}</a>{% if not forloop.last %}<br />{% endif %}
|
||||||
|
{% empty %}
|
||||||
|
—
|
||||||
|
{% endfor %}
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(template_code=self.template_code, *args, **kwargs)
|
||||||
|
|
||||||
|
def value(self, value):
|
||||||
|
prefixes = [str(prefix['prefix']) for prefix in value.all().values('prefix')]
|
||||||
|
return " ".join(prefixes) if prefixes else None
|
||||||
|
|
||||||
|
|
||||||
|
class VRFTargetsColumn(tables.TemplateColumn):
|
||||||
|
|
||||||
|
template_code = """
|
||||||
|
{% for rt in value.all %}
|
||||||
|
<a href="{{ rt.get_absolute_url }}">{{ rt }}</a>{% if not forloop.last %}<br />{% endif %}
|
||||||
|
{% empty %}
|
||||||
|
—
|
||||||
|
{% endfor %}
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(template_code=self.template_code, *args, **kwargs)
|
||||||
|
|
||||||
|
def value(self, value):
|
||||||
|
rts = [rd['name'] for rd in value.all().values('name')]
|
||||||
|
return " ".join(rts) if rts else None
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# VRFs
|
# VRFs
|
||||||
#
|
#
|
||||||
@ -122,12 +134,10 @@ class VRFTable(BaseTable):
|
|||||||
enforce_unique = BooleanColumn(
|
enforce_unique = BooleanColumn(
|
||||||
verbose_name='Unique'
|
verbose_name='Unique'
|
||||||
)
|
)
|
||||||
import_targets = tables.TemplateColumn(
|
import_targets = VRFTargetsColumn(
|
||||||
template_code=VRF_TARGETS,
|
|
||||||
orderable=False
|
orderable=False
|
||||||
)
|
)
|
||||||
export_targets = tables.TemplateColumn(
|
export_targets = VRFTargetsColumn(
|
||||||
template_code=VRF_TARGETS,
|
|
||||||
orderable=False
|
orderable=False
|
||||||
)
|
)
|
||||||
tags = TagColumn(
|
tags = TagColumn(
|
||||||
@ -295,8 +305,8 @@ class PrefixTable(BaseTable):
|
|||||||
linkify=True,
|
linkify=True,
|
||||||
verbose_name='VLAN'
|
verbose_name='VLAN'
|
||||||
)
|
)
|
||||||
role = tables.TemplateColumn(
|
role = tables.Column(
|
||||||
template_code=PREFIX_ROLE_LINK
|
linkify=True
|
||||||
)
|
)
|
||||||
is_pool = BooleanColumn(
|
is_pool = BooleanColumn(
|
||||||
verbose_name='Pool'
|
verbose_name='Pool'
|
||||||
@ -487,8 +497,8 @@ class VLANTable(BaseTable):
|
|||||||
status = ChoiceFieldColumn(
|
status = ChoiceFieldColumn(
|
||||||
default=AVAILABLE_LABEL
|
default=AVAILABLE_LABEL
|
||||||
)
|
)
|
||||||
role = tables.TemplateColumn(
|
role = tables.Column(
|
||||||
template_code=VLAN_ROLE_LINK
|
linkify=True
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
@ -500,8 +510,7 @@ class VLANTable(BaseTable):
|
|||||||
|
|
||||||
|
|
||||||
class VLANDetailTable(VLANTable):
|
class VLANDetailTable(VLANTable):
|
||||||
prefixes = tables.TemplateColumn(
|
prefixes = PrefixColumn(
|
||||||
template_code=VLAN_PREFIXES,
|
|
||||||
orderable=False,
|
orderable=False,
|
||||||
verbose_name='Prefixes'
|
verbose_name='Prefixes'
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user