mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Clean up boolean fields
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from django import forms
|
||||
|
||||
from netbox.config.parameters import PARAMS
|
||||
from netbox.config import get_config, PARAMS
|
||||
|
||||
__all__ = (
|
||||
'ConfigRevisionForm',
|
||||
@@ -13,18 +13,20 @@ EMPTY_VALUES = ('', None, [], ())
|
||||
class FormMetaclass(forms.models.ModelFormMetaclass):
|
||||
|
||||
def __new__(mcs, name, bases, attrs):
|
||||
config = get_config()
|
||||
|
||||
# Emulate a declared field for each supported configuration parameter
|
||||
param_fields = {}
|
||||
for param in PARAMS:
|
||||
help_text = f'{param.description}<br />' if param.description else ''
|
||||
# help_text += f'Current value: <strong>{getattr(settings, param.name)}</strong>'
|
||||
param_fields[param.name] = param.field(
|
||||
required=False,
|
||||
label=param.label,
|
||||
help_text=help_text,
|
||||
**param.field_kwargs
|
||||
)
|
||||
help_text += f'Current value: <strong>{getattr(config, param.name)}</strong>'
|
||||
field_kwargs = {
|
||||
'required': False,
|
||||
'label': param.label,
|
||||
'help_text': help_text,
|
||||
}
|
||||
field_kwargs.update(**param.field_kwargs)
|
||||
param_fields[param.name] = param.field(**field_kwargs)
|
||||
attrs.update(param_fields)
|
||||
|
||||
return super().__new__(mcs, name, bases, attrs)
|
||||
@@ -39,12 +41,6 @@ class ConfigRevisionForm(forms.BaseModelForm, metaclass=FormMetaclass):
|
||||
'comment': forms.Textarea(),
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Bugfix for django-timezone-field: Add empty choice to default options
|
||||
# self.fields['TIME_ZONE'].choices = [('', ''), *self.fields['TIME_ZONE'].choices]
|
||||
|
||||
def save(self, commit=True):
|
||||
instance = super().save(commit=False)
|
||||
|
||||
|
Reference in New Issue
Block a user