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:
@@ -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)
|
||||
]
|
||||
|
Reference in New Issue
Block a user