Skip to content

Commit

Permalink
Fix exporting of sources and destinations fields
Browse files Browse the repository at this point in the history
Avoid formating to HTML when exporting to CSV.
May still have issues with commas and quotes in object alias names.
  • Loading branch information
Alef-Burzmali committed Oct 27, 2024
1 parent 2243fac commit d9e4366
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
11 changes: 0 additions & 11 deletions netbox_data_flows/models/dataflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from ipam.constants import SERVICE_PORT_MAX, SERVICE_PORT_MIN

from netbox_data_flows.choices import DataFlowInheritedStatusChoices, DataFlowProtocolChoices, DataFlowStatusChoices
from netbox_data_flows.utils.helpers import object_list_to_string

from .groups import DataFlowGroup
from .objectaliases import ObjectAlias
Expand Down Expand Up @@ -160,16 +159,6 @@ def destination_port_list(self):

return array_to_string(self.destination_ports)

@property
def source_list(self):
sources = self.sources.all()
return object_list_to_string(sources, linkify=True)

@property
def destination_list(self):
destinations = self.destinations.all()
return object_list_to_string(destinations, linkify=True)

class Meta:
ordering = (
"application",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import django_tables2 as tables

from netbox.tables import columns

from netbox_data_flows.utils.helpers import object_list_to_string


class ObjectAliasListColumn(tables.Column):
"""Display the Object Aliases with links but export them without."""

def render(self, value):
return object_list_to_string(value.all(), linkify=True)

def value(self, value):
return object_list_to_string(value.all(), linkify=False, separator=",")


class RuntimeTemplateColumn(columns.TemplateColumn):
"""Allow setting the extra_context at runtime instead of model instantiation."""
Expand Down
14 changes: 6 additions & 8 deletions netbox_data_flows/tables/dataflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from netbox_data_flows.models import DataFlow

from .columns import ObjectAliasListColumn


__all__ = (
"DataFlowTable",
Expand Down Expand Up @@ -36,12 +38,10 @@ class DataFlowTable(NetBoxTable):
accessor=tables.A("destination_port_list"),
order_by=tables.A("destination_ports"),
)
sources = tables.Column(
accessor=tables.A("source_list"),
sources = ObjectAliasListColumn(
orderable=False,
)
destinations = tables.Column(
accessor=tables.A("destination_list"),
destinations = ObjectAliasListColumn(
orderable=False,
)

Expand Down Expand Up @@ -110,12 +110,10 @@ class DataFlowRuleTable(NetBoxTable):
accessor=tables.A("destination_port_list"),
order_by=tables.A("destination_ports"),
)
sources = tables.Column(
accessor=tables.A("source_list"),
sources = ObjectAliasListColumn(
orderable=False,
)
destinations = tables.Column(
accessor=tables.A("destination_list"),
destinations = ObjectAliasListColumn(
orderable=False,
)
tags = columns.TagColumn(url_name="plugins:netbox_data_flows:dataflow_rules")
Expand Down
3 changes: 2 additions & 1 deletion netbox_data_flows/tables/objectaliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from netbox.tables import NetBoxTable, columns

from netbox_data_flows.models import ObjectAlias, ObjectAliasTarget
from netbox_data_flows.utils.tables import RuntimeTemplateColumn

from .columns import RuntimeTemplateColumn


__all__ = (
Expand Down

0 comments on commit d9e4366

Please sign in to comment.