From 02abd5a8f76a1f175f1d13abf42fd32b1ec356ea Mon Sep 17 00:00:00 2001 From: Boris Sekachev <40690378+bsekachev@users.noreply.github.com> Date: Wed, 19 Dec 2018 17:56:52 +0300 Subject: [PATCH] Fixed labels order (#242) --- cvat/apps/engine/task.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cvat/apps/engine/task.py b/cvat/apps/engine/task.py index 7a735ae901de..786dfb0376a0 100644 --- a/cvat/apps/engine/task.py +++ b/cvat/apps/engine/task.py @@ -26,6 +26,7 @@ from ffmpy import FFmpeg from pyunpack import Archive from distutils.dir_util import copy_tree +from collections import OrderedDict from . import models from .log import slogger @@ -154,7 +155,7 @@ def get(tid): """Get the task as dictionary of attributes""" db_task = models.Task.objects.get(pk=tid) if db_task: - db_labels = db_task.label_set.prefetch_related('attributespec_set').all() + db_labels = db_task.label_set.prefetch_related('attributespec_set').order_by('-pk').all() im_meta_data = get_image_meta_cache(db_task) attributes = {} for db_label in db_labels: @@ -174,7 +175,7 @@ def get(tid): response = { "status": db_task.status, "spec": { - "labels": { db_label.id:db_label.name for db_label in db_labels }, + "labels": OrderedDict((db_label.id, db_label.name) for db_label in db_labels), "attributes": attributes }, "size": db_task.size, @@ -228,7 +229,7 @@ def get_job(jid): if db_task.mode == 'annotation': im_meta_data['original_size'] = im_meta_data['original_size'][db_segment.start_frame:db_segment.stop_frame + 1] - db_labels = db_task.label_set.prefetch_related('attributespec_set').all() + db_labels = db_task.label_set.prefetch_related('attributespec_set').order_by('-pk').all() attributes = {} for db_label in db_labels: attributes[db_label.id] = {} @@ -237,7 +238,7 @@ def get_job(jid): response = { "status": db_job.status, - "labels": { db_label.id:db_label.name for db_label in db_labels }, + "labels": OrderedDict((db_label.id, db_label.name) for db_label in db_labels), "stop": db_segment.stop_frame, "taskid": db_task.id, "slug": db_task.name, @@ -375,7 +376,7 @@ def _get_frame_path(frame, base_dir): return path def _parse_labels(labels): - parsed_labels = {} + parsed_labels = OrderedDict() last_label = "" for token in shlex.split(labels):