summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2022-09-22 17:37:10 +0200
committerJavier Sánchez Parra <jsanchez@soleta.eu>2022-09-29 13:01:28 +0200
commit328ead91682d0f0a9a918032b7de69de801954ec (patch)
tree988898e610053f55a93459550b295ab972ccee21
parent178f253092c2dd8ce5ab81089e27952b19757203 (diff)
Create servers list if do not exists
Otherwise, if the configuration file do not have 'SERVERS' array, ogCP crashes trying to append a new server.
-rw-r--r--ogcp/views.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index cc6c2a3..862cc3e 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -1507,7 +1507,11 @@ def save_server(form):
with open(filename, 'r+') as file:
config = json.load(file)
- config['SERVERS'].append(server_dict)
+ try:
+ config['SERVERS'].append(server_dict)
+ except KeyError:
+ config['SERVERS'] = list()
+ config['SERVERS'].append(server_dict)
file.seek(0)
json.dump(config, file, indent='\t')