Skip to content

Conversation

pheus
Copy link
Contributor

@pheus pheus commented Oct 9, 2025

Fixes: #20516

Summary

  • Add ranges_to_string_list(ranges) -> list[str], which formats numeric ranges as human‑readable strings (e.g., ["1-5", "8", "10-12"]).
  • Refactor ranges_to_string(ranges) to delegate to the new helper:
    if not ranges:
        return ''
    return ','.join(ranges_to_string_list(ranges))
    This preserves the existing output (comma‑separated with no spaces) while enabling callers to control separators when needed.
  • Improve VLAN Group rendering by switching the table column to use a list accessor with ArrayColumn, yielding ", " spacing in the UI without changing underlying data or the string helper’s behavior.

Implementation notes

  • ranges_to_string remains fully backward‑compatible in both signature and output.
  • VLAN Group table uses a list accessor (e.g., vid_ranges_items) with ArrayColumn, while keeping the existing vid_ranges_list string property available to avoid breaking saved table configs.

Testing

  • Add unit tests covering:
    • Singleton ranges ("8") vs. hyphen ranges ("1-5")
    • ranges_to_string_list()

Backwards compatibility

  • No breaking changes. Existing uses of ranges_to_string() and VLANGroup.vid_ranges_list continue to work as before.

Introduce `ranges_to_string_list` for converting numeric ranges into a
list of readable strings. Update the `vid_ranges_list` property and
templates to use this method for better readability and maintainability.
Add related tests to ensure functionality.

Closes netbox-community#20516
@jeremystretch jeremystretch requested review from a team and jeremystretch and removed request for a team October 9, 2025 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Render VLAN Group VID ranges with ArrayColumn

1 participant