mirror of
https://github.com/netbox-community/netbox.git
synced 2026-03-30 06:12:13 +02:00
- Use verbose labels (App | Model) for action group headers - Simplify template layout with h5 headers instead of cards - Consolidate Standard/Custom/Additional Actions into single Actions fieldset
41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
from django import forms
|
|
from django.apps import apps
|
|
|
|
__all__ = (
|
|
'RegisteredActionsWidget',
|
|
)
|
|
|
|
|
|
class RegisteredActionsWidget(forms.CheckboxSelectMultiple):
|
|
"""
|
|
Widget rendering checkboxes for registered model actions.
|
|
Groups actions by model with data attributes for JS show/hide.
|
|
"""
|
|
template_name = 'widgets/registered_actions.html'
|
|
|
|
def __init__(self, *args, model_actions=None, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.model_actions = model_actions or {}
|
|
|
|
def get_context(self, name, value, attrs):
|
|
context = super().get_context(name, value, attrs)
|
|
|
|
# Build model_actions with labels for v2 template
|
|
model_actions_with_labels = {}
|
|
for model_key, actions in self.model_actions.items():
|
|
app_label, model_name = model_key.split('.')
|
|
try:
|
|
model = apps.get_model(app_label, model_name)
|
|
app_config = apps.get_app_config(app_label)
|
|
label = f"{app_config.verbose_name} | {model._meta.verbose_name.title()}"
|
|
except LookupError:
|
|
label = model_key
|
|
model_actions_with_labels[model_key] = {
|
|
'label': label,
|
|
'actions': actions,
|
|
}
|
|
|
|
context['widget']['model_actions'] = model_actions_with_labels
|
|
context['widget']['value'] = value or []
|
|
return context
|