Skip to content

Commit

Permalink
Fix #43: Format ports as ranges in edit forms
Browse files Browse the repository at this point in the history
  • Loading branch information
Alef-Burzmali committed Oct 27, 2024
1 parent d9e4366 commit 55b692b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion netbox_data_flows/forms/dataflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
CSVModelMultipleChoiceField,
DynamicModelChoiceField,
DynamicModelMultipleChoiceField,
NumericArrayField,
TagFilterField,
)
from utilities.forms.rendering import FieldSet
Expand All @@ -21,6 +20,8 @@

from netbox_data_flows import choices, models

from .fields import NumericArrayField


__all__ = (
"DataFlowForm",
Expand All @@ -29,6 +30,7 @@
"DataFlowFilterForm",
)


#
# Object forms
#
Expand Down
18 changes: 18 additions & 0 deletions netbox_data_flows/forms/fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from utilities.data import array_to_string
from utilities.forms.fields import NumericArrayField as NumericArrayField_


__all__ = ("NumericArrayField",)


class NumericArrayField(NumericArrayField_):
"""Format ranges in a human-friendly way before displaying the field."""

def prepare_value(self, value):
if not value:
return ""

if isinstance(value, str):
return value

return array_to_string(value)

0 comments on commit 55b692b

Please sign in to comment.