From 6755a340e335b027e955158bb1cda470f9967f6c Mon Sep 17 00:00:00 2001 From: noracato Date: Fri, 31 Mar 2023 14:08:03 +0200 Subject: [PATCH] Optionally supply a scenario ID to `create` to update a scenario instead Closes #93 --- app/api/v1/create_scenario.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/api/v1/create_scenario.py b/app/api/v1/create_scenario.py index 5a19275..a357046 100644 --- a/app/api/v1/create_scenario.py +++ b/app/api/v1/create_scenario.py @@ -27,6 +27,13 @@ location='form' ) import_parser.add_argument('energy_system_title', type=str, required=False, location='form') +import_parser.add_argument( + 'scenario_id', + type=int, + required=False, + location='form', + help='If you want to update an existing scenario instead of creating an ew one, please specify the ID here.' +) ## Controller @api.route('/') @@ -48,7 +55,12 @@ def post(self): ) converter = EsdlToScenarioConverter(self.energy_system_handler) - self.__create_new_scenario_id(converter.area) + + # NOTE: we don't validate if this scenario matches the area! + if args['scenario_id']: + self.scenario_id = args['scenario_id'] + else: + self.__create_new_scenario_id(converter.area) with HaltGarbageCollection(): self.__set_sliders_in_etm(self.__filter_on_hold(converter.calculate()))