1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Enable tabbed group fields in fieldsets

This commit is contained in:
Jeremy Stretch
2024-03-12 17:02:26 -04:00
parent f585c36d86
commit 4c7b6fcec0
6 changed files with 92 additions and 121 deletions

View File

@@ -1,10 +1,43 @@
import random
import string
from functools import cached_property
__all__ = (
'FieldGroup',
'InlineFields',
'TabbedFieldGroups',
)
class InlineFields:
class FieldGroup:
def __init__(self, *field_names, label=None):
def __init__(self, label, *field_names):
self.field_names = field_names
self.label = label
class InlineFields(FieldGroup):
pass
class TabbedFieldGroups:
def __init__(self, *groups):
self.groups = [
FieldGroup(*group) for group in groups
]
# Initialize a random ID for the group (for tab selection)
self.id = ''.join(
random.choice(string.ascii_lowercase + string.digits) for _ in range(8)
)
@cached_property
def tabs(self):
return [
{
'id': f'{self.id}_{i}',
'title': group.label,
'fields': group.field_names,
} for i, group in enumerate(self.groups, start=1)
]