catch invalid config values for enum dropdowns and reset to default
This commit is contained in:
parent
818b9d87b8
commit
9689ce5202
@ -61,7 +61,14 @@ class EnumConverter(Converter):
|
|||||||
self.enumCls = enumCls
|
self.enumCls = enumCls
|
||||||
|
|
||||||
def convert_to_form(self, value):
|
def convert_to_form(self, value):
|
||||||
return None if value is None else self.enumCls(value).name
|
if value is None:
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
return self.enumCls(value).name
|
||||||
|
# if the current value is not part of the enum, this will happen:
|
||||||
|
except ValueError:
|
||||||
|
# and this will restore the default
|
||||||
|
return None
|
||||||
|
|
||||||
def convert_from_form(self, value):
|
def convert_from_form(self, value):
|
||||||
return self.enumCls[value].value
|
return self.enumCls[value].value
|
||||||
|
Loading…
Reference in New Issue
Block a user