mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Enable setting/clearing of table column prefs
This commit is contained in:
@ -137,27 +137,6 @@ def form_from_model(model, fields):
|
||||
return type('FormFromModel', (forms.Form,), form_fields)
|
||||
|
||||
|
||||
def apply_bootstrap_classes(form):
|
||||
"""
|
||||
Apply Bootstrap CSS classes to form elements.
|
||||
"""
|
||||
exempt_widgets = [
|
||||
forms.CheckboxInput,
|
||||
forms.ClearableFileInput,
|
||||
forms.FileInput,
|
||||
forms.RadioSelect
|
||||
]
|
||||
|
||||
for field_name, field in form.fields.items():
|
||||
if field.widget.__class__ not in exempt_widgets:
|
||||
css = field.widget.attrs.get('class', '')
|
||||
field.widget.attrs['class'] = ' '.join([css, 'form-control']).strip()
|
||||
if field.required and not isinstance(field.widget, forms.FileInput):
|
||||
field.widget.attrs['required'] = 'required'
|
||||
if 'placeholder' not in field.widget.attrs:
|
||||
field.widget.attrs['placeholder'] = field.label
|
||||
|
||||
|
||||
#
|
||||
# Widgets
|
||||
#
|
||||
@ -684,7 +663,22 @@ class BootstrapMixin(forms.BaseForm):
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
apply_bootstrap_classes(self)
|
||||
|
||||
exempt_widgets = [
|
||||
forms.CheckboxInput,
|
||||
forms.ClearableFileInput,
|
||||
forms.FileInput,
|
||||
forms.RadioSelect
|
||||
]
|
||||
|
||||
for field_name, field in self.fields.items():
|
||||
if field.widget.__class__ not in exempt_widgets:
|
||||
css = field.widget.attrs.get('class', '')
|
||||
field.widget.attrs['class'] = ' '.join([css, 'form-control']).strip()
|
||||
if field.required and not isinstance(field.widget, forms.FileInput):
|
||||
field.widget.attrs['required'] = 'required'
|
||||
if 'placeholder' not in field.widget.attrs:
|
||||
field.widget.attrs['placeholder'] = field.label
|
||||
|
||||
|
||||
class ReturnURLForm(forms.Form):
|
||||
@ -763,21 +757,20 @@ class ImportForm(BootstrapMixin, forms.Form):
|
||||
})
|
||||
|
||||
|
||||
class TableConfigForm(forms.Form):
|
||||
class TableConfigForm(BootstrapMixin, forms.Form):
|
||||
"""
|
||||
Form for configuring user's table preferences.
|
||||
"""
|
||||
columns = forms.MultipleChoiceField(
|
||||
choices=[],
|
||||
widget=forms.SelectMultiple(
|
||||
attrs={'size': 10}
|
||||
)
|
||||
)
|
||||
|
||||
def __init__(self, table, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
field_name = f"tables.{table.__class__.__name__}.columns"
|
||||
self.fields[field_name] = forms.MultipleChoiceField(
|
||||
choices=table.configurable_columns,
|
||||
initial=table.visible_columns,
|
||||
label='Columns',
|
||||
widget=forms.SelectMultiple(
|
||||
attrs={'size': 10}
|
||||
)
|
||||
)
|
||||
|
||||
apply_bootstrap_classes(self)
|
||||
# Initialize columns field based on table attributes
|
||||
self.fields['columns'].choices = table.configurable_columns
|
||||
self.fields['columns'].initial = table.visible_columns
|
||||
|
Reference in New Issue
Block a user