Skip to content

Commit

Permalink
feat: allow to update Collection
Browse files Browse the repository at this point in the history
  • Loading branch information
lubojr committed Sep 1, 2023
1 parent f29832e commit 89f7116
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions eoxserver/resources/coverages/management/commands/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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:
Expand All @@ -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)

Expand Down

0 comments on commit 89f7116

Please sign in to comment.