Skip to content

Commit

Permalink
Improve update for the task.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmanovic committed Feb 6, 2019
1 parent a4054a0 commit 3e87bc3
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions cvat/apps/engine/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from rest_framework import serializers
from cvat.apps.engine.models import (Task, Job, Label, AttributeSpec,
Segment, ClientFile, ServerFile, RemoteFile, Plugin)
from cvat.apps.engine.log import slogger

from django.contrib.auth.models import User, Group
import os
Expand Down Expand Up @@ -209,13 +210,34 @@ def update(self, instance, validated_data):
instance.flipped = validated_data.get('flipped', instance.flipped)
instance.image_quality = validated_data.get('image_quality',
instance.image_quality)
labels = validated_data.get('label_set')
labels = validated_data.get('label_set', [])
for label in labels:
attributes = label.pop('attributespec_set')
(db_label, _) = Label.objects.get_or_create(task=instance, **label)
attributes = label.pop('attributespec_set', [])
(db_label, created) = Label.objects.get_or_create(task=instance,
name=label['name'])
if created:
slogger.task[instance.id].info("New {} label was created"
.format(db_label.name))
else:
slogger.task[instance.id].info("{} label was updated"
.format(db_label.name))
for attr in attributes:
(db_attr, created) = AttributeSpec.objects.get_or_create(
label=db_label, **attr)
label=db_label, name=attr['name'], defaults=attr)
if created:
slogger.task[instance.id].info("New {} attribute for {} label was created"
.format(db_attr.name, db_label.name))
else:
slogger.task[instance.id].info("{} attribute for {} label was updated"
.format(db_attr.name, db_label.name))

# FIXME: need to update only "safe" fields
db_attr.default_value = attr.get('default_value', db_attr.default_value)
db_attr.mutable = attr.get('mutable', db_attr.mutable)
db_attr.input_type = attr.get('input_type', db_attr.input_type)
db_attr.values = attr.get('values', db_attr.values)
db_attr.save()




Expand Down

0 comments on commit 3e87bc3

Please sign in to comment.