Skip to content

Commit

Permalink
Set annotations metadata to datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbroks committed Apr 13, 2019
1 parent 95e5267 commit 55a5acc
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion backend/webserver/api/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
update_dataset = reqparse.RequestParser()
update_dataset.add_argument('categories', location='json', type=list, help="New list of categories")
update_dataset.add_argument('default_annotation_metadata', location='json', type=dict,
help="Default annotation metadata")
help="Default annotation metadata")

dataset_generate = reqparse.RequestParser()
dataset_generate.add_argument('keywords', location='json', type=list, default=[],
Expand Down Expand Up @@ -193,20 +193,31 @@ def delete(self, dataset_id):

@api.expect(update_dataset)
def post(self, dataset_id):

""" Updates dataset by ID """

dataset = current_user.datasets.filter(id=dataset_id, deleted=False).first()
if dataset is None:
return {"message": "Invalid dataset id"}, 400

args = update_dataset.parse_args()
categories = args.get('categories')
default_annotation_metadata = args.get('default_annotation_metadata')
set_default_annotation_metadata = args.get('set_default_annotation_metadata')

if categories is not None:
dataset.categories = CategoryModel.bulk_create(categories)

if default_annotation_metadata is not None:

update = {}
for key, value in default_annotation_metadata.items():
if key not in dataset.default_annotation_metadata:
update[f'set__metadata__{key}'] = value

dataset.default_annotation_metadata = default_annotation_metadata
AnnotationModel.objects(dataset_id=dataset.id, deleted=False)\
.update(**update)

dataset.update(
categories=dataset.categories,
Expand Down

0 comments on commit 55a5acc

Please sign in to comment.