Allow individual App Settings to not be required; allow null
hopefully this does the right thing also, not saving null to the db when that isn't needed etc.
This commit is contained in:
parent
f1eba6a404
commit
b9da7e1b12
|
@ -140,6 +140,10 @@ class AppSettingsView(View):
|
||||||
'name': setting.node_name,
|
'name': setting.node_name,
|
||||||
'default': self.get_setting_value(setting),
|
'default': self.get_setting_value(setting),
|
||||||
}
|
}
|
||||||
|
if kwargs['default'] is None:
|
||||||
|
kwargs['default'] = colander.null
|
||||||
|
if not setting.required:
|
||||||
|
kwargs['missing'] = colander.null
|
||||||
if setting.choices:
|
if setting.choices:
|
||||||
kwargs['validator'] = colander.OneOf(setting.choices)
|
kwargs['validator'] = colander.OneOf(setting.choices)
|
||||||
kwargs['widget'] = forms.widgets.JQuerySelectWidget(
|
kwargs['widget'] = forms.widgets.JQuerySelectWidget(
|
||||||
|
@ -151,11 +155,15 @@ class AppSettingsView(View):
|
||||||
def get_node_type(self, setting):
|
def get_node_type(self, setting):
|
||||||
if setting.data_type is bool:
|
if setting.data_type is bool:
|
||||||
return colander.Bool()
|
return colander.Bool()
|
||||||
|
elif setting.data_type is int:
|
||||||
|
return colander.Integer()
|
||||||
return colander.String()
|
return colander.String()
|
||||||
|
|
||||||
def save_form(self, form):
|
def save_form(self, form):
|
||||||
for setting in self.iter_known_settings():
|
for setting in self.iter_known_settings():
|
||||||
value = form.validated[setting.node_name]
|
value = form.validated[setting.node_name]
|
||||||
|
if value is colander.null:
|
||||||
|
value = None
|
||||||
self.save_setting_value(setting, value)
|
self.save_setting_value(setting, value)
|
||||||
|
|
||||||
def iter_known_settings(self):
|
def iter_known_settings(self):
|
||||||
|
|
Loading…
Reference in a new issue