Closes #20516: Add ranges_to_string_list and render VLAN Group VID ranges with ArrayColumn #1094

Closed
opened 2026-04-05 20:34:47 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @pheus on 10/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.
*Originally created by @pheus on 10/9/2025* <!-- Thank you for your interest in contributing to NetBox! Please note that our contribution policy requires that a feature request or bug report be approved and assigned prior to opening a pull request. This helps avoid waste time and effort on a proposed change that we might not be able to accept. IF YOUR PULL REQUEST DOES NOT REFERENCE AN ISSUE WHICH HAS BEEN ASSIGNED TO YOU, IT WILL BE CLOSED AUTOMATICALLY. Please specify your assigned issue number on the line below. --> ### Fixes: #20516 <!-- Please include a summary of the proposed changes below. --> **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: ```py 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.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#1094