aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim/webui/handlers/configs.py
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-11-22 09:34:05 +0800
committerAaron LI <aaronly.me@outlook.com>2016-11-22 09:34:05 +0800
commitb542121fa90041ea457dd605feaca7077a8f6bc4 (patch)
tree2ac49bd844c75061bc7599f59db9c277b3d7503b /fg21sim/webui/handlers/configs.py
parent4d7072d5b15c7bb2a2260c4f1566950f6220fb38 (diff)
downloadfg21sim-b542121fa90041ea457dd605feaca7077a8f6bc4.tar.bz2
webui: configs: Some minor fixes
* configs.py/_set_configs(): Also return the original data if the input values failed the validation; * setServerConfigs(): Success callback also reset value if the input value failed pass the server-side validation; * getServerConfigs(): Return "undefined" if key does not exists.
Diffstat (limited to 'fg21sim/webui/handlers/configs.py')
-rw-r--r--fg21sim/webui/handlers/configs.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/fg21sim/webui/handlers/configs.py b/fg21sim/webui/handlers/configs.py
index 296bd11..857138b 100644
--- a/fg21sim/webui/handlers/configs.py
+++ b/fg21sim/webui/handlers/configs.py
@@ -99,7 +99,7 @@ class ConfigsAJAXHandler(BaseRequestHandler):
if action == "set":
# Set the values of the specified options
try:
- errors = self._set_configs(data=request["data"])
+ data, errors = self._set_configs(request["data"])
success = True
except KeyError:
success = False
@@ -198,10 +198,15 @@ class ConfigsAJAXHandler(BaseRequestHandler):
Returns
-------
+ data_orig : dict
+ When the supplied value failed to pass the specification
+ validation, then its original value was returned to the client
+ to reset its value.
errors : dict
When error occurs (e.g., invalid key, invalid values), then the
specific errors with details are stored in this dictionary.
"""
+ data_orig = {}
errors = {}
for key, value in data.items():
if key in ["workdir", "configfile"]:
@@ -215,10 +220,13 @@ class ConfigsAJAXHandler(BaseRequestHandler):
else:
try:
self.configs.setn(key, value)
- except (KeyError, ConfigError) as e:
+ except KeyError as e:
+ errors[key] = str(e)
+ except ConfigError as e:
+ data_orig[key] = self.configs.getn(key)
errors[key] = str(e)
#
- return errors
+ return (data_orig, errors)
def _reset_configs(self):
"""Reset the configurations to the defaults."""