diff --git a/netbox/extras/forms/config.py b/netbox/extras/forms/config.py
index 001252f0c..60a19c9a8 100644
--- a/netbox/extras/forms/config.py
+++ b/netbox/extras/forms/config.py
@@ -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}
' if param.description else ''
- # help_text += f'Current value: {getattr(settings, param.name)}'
- param_fields[param.name] = param.field(
- required=False,
- label=param.label,
- help_text=help_text,
- **param.field_kwargs
- )
+ help_text += f'Current value: {getattr(config, param.name)}'
+ 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)
diff --git a/netbox/netbox/config/parameters.py b/netbox/netbox/config/parameters.py
index e09466839..da9294ad0 100644
--- a/netbox/netbox/config/parameters.py
+++ b/netbox/netbox/config/parameters.py
@@ -2,23 +2,6 @@ from django import forms
from django.contrib.postgres.forms import SimpleArrayField
-class OptionalBooleanSelect(forms.Select):
- """
- An optional boolean field (yes/no/default).
- """
- def __init__(self, attrs=None):
- choices = (
- ('', 'Default'),
- (True, 'Yes'),
- (False, 'No'),
- )
- super().__init__(attrs, choices)
-
-
-class OptionalBooleanField(forms.NullBooleanField):
- widget = OptionalBooleanSelect
-
-
class ConfigParam:
def __init__(self, name, label, default, description=None, field=None, field_kwargs=None):
@@ -43,14 +26,14 @@ PARAMS = (
label='Globally unique IP space',
default=False,
description="Enforce unique IP addressing within the global table",
- field=OptionalBooleanField
+ field=forms.BooleanField
),
ConfigParam(
name='PREFER_IPV4',
label='Prefer IPv4',
default=False,
description="Prefer IPv4 addresses over IPv6",
- field=OptionalBooleanField
+ field=forms.BooleanField
),
# Racks
@@ -127,7 +110,7 @@ PARAMS = (
label='Maintenance mode',
default=False,
description="Enable maintenance mode",
- field=OptionalBooleanField
+ field=forms.BooleanField
),
ConfigParam(
name='MAPS_URL',