|
|
@@ -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)
|
|
|
|