From 89f7116f9c8067164de0ebfbfb4a03b893a90968 Mon Sep 17 00:00:00 2001 From: Lubomir Dolezal Date: Fri, 1 Sep 2023 12:06:05 +0200 Subject: [PATCH] feat: allow to update Collection --- .../management/commands/collection.py | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/eoxserver/resources/coverages/management/commands/collection.py b/eoxserver/resources/coverages/management/commands/collection.py index e5a4cfb0f..f4cfab4e3 100644 --- a/eoxserver/resources/coverages/management/commands/collection.py +++ b/eoxserver/resources/coverages/management/commands/collection.py @@ -73,6 +73,14 @@ def add_arguments(self, parser): '"platform".' ) ) + create_parser.add_argument( + '--replace', action='store_true', + default=False, + help=( + '''Change collection type references according to parameters + if collection type already exists.''' + ) + ) delete_parser.add_argument( '--all', '-a', action="store_true", default=False, dest='all_collections', @@ -155,7 +163,7 @@ def handle(self, subcommand, identifier, *args, **kwargs): elif subcommand == "summary": self.handle_summary(identifier[0], *args, **kwargs) - def handle_create(self, identifier, type_name, grid_name, **kwargs): + def handle_create(self, identifier, type_name, grid_name, replace, **kwargs): """ Handle the creation of a new collection. """ if grid_name: @@ -176,11 +184,18 @@ def handle_create(self, identifier, type_name, grid_name, **kwargs): raise CommandError( "Collection type %r does not exist." % type_name ) - - models.Collection.objects.create( - identifier=identifier, - collection_type=collection_type, grid=grid - ) + if replace: + models.Collection.objects.update_or_create( + identifier=identifier, + defaults={ + 'collection_type':collection_type, + 'grid':grid, + } + ) + else: + models.Collection.objects.create( + identifier=identifier, collection_type=collection_type, grid=grid + ) print('Successfully created collection %r' % identifier)