[PR #20548] [MERGED] Closes #20516: Add ranges_to_string_list and render VLAN Group VID ranges with ArrayColumn #15960

Closed
opened 2025-12-30 00:25:01 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/20548
Author: @pheus
Created: 10/9/2025
Status: Merged
Merged: 10/14/2025
Merged by: @jeremystretch

Base: mainHead: 20516-render-vlangroup-id-with-arraycolumn


📝 Commits (1)

  • dcd6aa5 feat(utilities): Add ranges_to_string_list

📊 Changes

5 files changed (+67 additions, -17 deletions)

View changed files

📝 netbox/ipam/models/vlans.py (+12 -2)
📝 netbox/ipam/tables/vlans.py (+2 -1)
📝 netbox/templates/ipam/vlangroup.html (+1 -1)
📝 netbox/utilities/data.py (+33 -10)
📝 netbox/utilities/tests/test_data.py (+19 -3)

📄 Description

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/20548 **Author:** [@pheus](https://github.com/pheus) **Created:** 10/9/2025 **Status:** ✅ Merged **Merged:** 10/14/2025 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `main` ← **Head:** `20516-render-vlangroup-id-with-arraycolumn` --- ### 📝 Commits (1) - [`dcd6aa5`](https://github.com/netbox-community/netbox/commit/dcd6aa56cd82811782c1da7a3826f335deba938e) feat(utilities): Add ranges_to_string_list ### 📊 Changes **5 files changed** (+67 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `netbox/ipam/models/vlans.py` (+12 -2) 📝 `netbox/ipam/tables/vlans.py` (+2 -1) 📝 `netbox/templates/ipam/vlangroup.html` (+1 -1) 📝 `netbox/utilities/data.py` (+33 -10) 📝 `netbox/utilities/tests/test_data.py` (+19 -3) </details> ### 📄 Description <!-- 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:25:01 +01:00
adam closed this issue 2025-12-30 00:25:01 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15960