|
@@ -14,25 +14,14 @@ EMPTY_VALUES = ('', None, [], ())
|
|
|
class FormMetaclass(forms.models.ModelFormMetaclass):
|
|
class FormMetaclass(forms.models.ModelFormMetaclass):
|
|
|
|
|
|
|
|
def __new__(mcs, name, bases, attrs):
|
|
def __new__(mcs, name, bases, attrs):
|
|
|
- config = get_config()
|
|
|
|
|
|
|
|
|
|
# Emulate a declared field for each supported configuration parameter
|
|
# Emulate a declared field for each supported configuration parameter
|
|
|
param_fields = {}
|
|
param_fields = {}
|
|
|
for param in PARAMS:
|
|
for param in PARAMS:
|
|
|
- is_static = hasattr(settings, param.name)
|
|
|
|
|
- help_text = f'{param.description}<br />' if param.description else ''
|
|
|
|
|
- value = getattr(config, param.name)
|
|
|
|
|
- if value:
|
|
|
|
|
- help_text += f'Current value: <strong>{value}</strong>'
|
|
|
|
|
- if is_static:
|
|
|
|
|
- help_text += ' (defined statically)'
|
|
|
|
|
- elif value == param.default:
|
|
|
|
|
- help_text += ' (default)'
|
|
|
|
|
field_kwargs = {
|
|
field_kwargs = {
|
|
|
'required': False,
|
|
'required': False,
|
|
|
- 'disabled': is_static,
|
|
|
|
|
'label': param.label,
|
|
'label': param.label,
|
|
|
- 'help_text': help_text,
|
|
|
|
|
|
|
+ 'help_text': param.description,
|
|
|
}
|
|
}
|
|
|
field_kwargs.update(**param.field_kwargs)
|
|
field_kwargs.update(**param.field_kwargs)
|
|
|
param_fields[param.name] = param.field(**field_kwargs)
|
|
param_fields[param.name] = param.field(**field_kwargs)
|
|
@@ -50,6 +39,24 @@ class ConfigRevisionForm(forms.BaseModelForm, metaclass=FormMetaclass):
|
|
|
'comment': forms.Textarea(),
|
|
'comment': forms.Textarea(),
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ def __init__(self, *args, **kwargs):
|
|
|
|
|
+ super().__init__(*args, **kwargs)
|
|
|
|
|
+
|
|
|
|
|
+ # Append current parameter values to form field help texts and check for static configurations
|
|
|
|
|
+ config = get_config()
|
|
|
|
|
+ for param in PARAMS:
|
|
|
|
|
+ value = getattr(config, param.name)
|
|
|
|
|
+ is_static = hasattr(settings, param.name)
|
|
|
|
|
+ if value:
|
|
|
|
|
+ help_text = f'<br />Current value: <strong>{value}</strong>'
|
|
|
|
|
+ if is_static:
|
|
|
|
|
+ help_text += ' (defined statically)'
|
|
|
|
|
+ elif value == param.default:
|
|
|
|
|
+ help_text += ' (default)'
|
|
|
|
|
+ self.fields[param.name].help_text += help_text
|
|
|
|
|
+ if is_static:
|
|
|
|
|
+ self.fields[param.name].disabled = True
|
|
|
|
|
+
|
|
|
def save(self, commit=True):
|
|
def save(self, commit=True):
|
|
|
instance = super().save(commit=False)
|
|
instance = super().save(commit=False)
|
|
|
|
|
|