Use FieldSet instances for all forms

This commit is contained in:
Jeremy Stretch
2024-03-18 15:08:28 -04:00
parent 3b28e8e615
commit 72d3c17b48
35 changed files with 800 additions and 757 deletions

View File

@@ -33,10 +33,11 @@ class TabbedGroups:
"""
Two or more groups of fields (FieldSets) arranged under tabs among which the user can navigate.
"""
def __init__(self, *groups):
self.groups = [
FieldSet(*group, name=name) for name, *group in groups
]
def __init__(self, *fieldsets):
for fs in fieldsets:
if not fs.name:
raise ValueError(f"Grouped fieldset {fs} must have a name.")
self.groups = fieldsets
# Initialize a random ID for the group (for tab selection)
self.id = ''.join(

View File

@@ -1,3 +1,5 @@
import warnings
from django import template
from utilities.forms.rendering import FieldSet, InlineFields, ObjectAttribute, TabbedGroups
@@ -52,8 +54,12 @@ def render_fieldset(form, fieldset):
"""
Render a group set of fields.
"""
# TODO: Remove in NetBox v4.1
# Handle legacy tuple-based fieldset definitions, e.g. (_('Label'), ('field1, 'field2', 'field3'))
if type(fieldset) is not FieldSet:
warnings.warn(
f"{form.__class__} fieldsets contains a non-FieldSet item: {fieldset}"
)
name, fields = fieldset
fieldset = FieldSet(*fields, name=name)