mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-19 03:42:25 -06:00
Use FieldSet instances for all forms
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user