2023-02-24 16:04:00 -05:00
|
|
|
from django import forms
|
|
|
|
from django.urls import reverse_lazy
|
2023-03-22 15:44:01 -04:00
|
|
|
from django.utils.translation import gettext as _
|
2023-02-24 16:04:00 -05:00
|
|
|
|
|
|
|
from netbox.registry import registry
|
|
|
|
from utilities.forms import BootstrapMixin, add_blank_choice
|
|
|
|
from utilities.choices import ButtonColorChoices
|
|
|
|
|
|
|
|
__all__ = (
|
|
|
|
'DashboardWidgetAddForm',
|
|
|
|
'DashboardWidgetForm',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def get_widget_choices():
|
|
|
|
return registry['widgets'].items()
|
|
|
|
|
|
|
|
|
|
|
|
class DashboardWidgetForm(BootstrapMixin, forms.Form):
|
|
|
|
title = forms.CharField(
|
|
|
|
required=False
|
|
|
|
)
|
|
|
|
color = forms.ChoiceField(
|
|
|
|
choices=add_blank_choice(ButtonColorChoices),
|
|
|
|
required=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class DashboardWidgetAddForm(DashboardWidgetForm):
|
|
|
|
widget_class = forms.ChoiceField(
|
|
|
|
choices=get_widget_choices,
|
|
|
|
widget=forms.Select(
|
|
|
|
attrs={
|
|
|
|
'hx-get': reverse_lazy('extras:dashboardwidget_add'),
|
|
|
|
'hx-target': '#widget_add_form',
|
|
|
|
}
|
2023-03-22 15:44:01 -04:00
|
|
|
),
|
|
|
|
label=_('Widget type')
|
2023-02-24 16:04:00 -05:00
|
|
|
)
|
|
|
|
field_order = ('widget_class', 'title', 'color')
|