Skip to content

Commit

Permalink
Got idea to separate FileUpload and Json part.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Manovich committed Feb 1, 2019
1 parent 5f27325 commit 4feb191
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
6 changes: 3 additions & 3 deletions cvat/apps/dashboard/static/dashboard/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,11 @@ function setupTaskCreator() {
taskData.append("image_quality", compressQuality);
}

for (let file of files) {
for (let j = 0; j < files.length; j++) {
if (source === "local") {
taskData.append("client_files", file);
taskData.append(`client_files[${j}]`, files[j]);
} else {
taskData.append("server_files", file);
taskData.append(`server_files[${j}]`, files[j]);
}
}

Expand Down
4 changes: 2 additions & 2 deletions cvat/apps/engine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ def __str__(self):
return self.name

def upload_path_handler(instance, filename):
return os.path.join(instance.get_upload_dirname(), filename)
return os.path.join(instance.task.get_upload_dirname(), filename)

# For client files which the user is uploaded
class ClientFile(models.Model):
task = models.ForeignKey(Task, on_delete=models.CASCADE)
file = models.FileField(upload_to=upload_path_handler,
storage=FileSystemStorage)
storage=FileSystemStorage())

class Meta:
default_permissions = ()
Expand Down
16 changes: 9 additions & 7 deletions cvat/apps/engine/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Meta:
class ClientFileSerializer(serializers.ModelSerializer):
class Meta:
model = ClientFile
fields = ('path', )
fields = ('file', )

def to_internal_value(self, data):
return { 'file': data }
Expand Down Expand Up @@ -121,14 +121,16 @@ def create(self, validated_data):
for attr in attributes:
AttributeSpec.objects.create(label=db_label, **attr)

for file in client_files:
ClientFile.objects.create(task=db_task, file=file)
for obj in client_files:
serializer = ClientFileSerializer(data=obj['file'])
if serializer.is_valid(raise_exception=True):
serializer.save()

for file in server_files:
ServerFile.objects.create(task=db_task, file=file)
for path in server_files:
ServerFile.objects.create(task=db_task, file=path)

for file in remote_files:
RemoteFile.objects.create(task=db_task, file=file)
for path in remote_files:
RemoteFile.objects.create(task=db_task, file=path)

task_path = db_task.get_task_dirname()
if os.path.isdir(task_path):
Expand Down
2 changes: 1 addition & 1 deletion cvat/apps/engine/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def create(tid, params):
"""Schedule the task"""
q = django_rq.get_queue('default')
q.enqueue_call(func=_create_thread, args=(tid, params),
job_id="task.create/{}".format(tid))
job_id="/api/v1/tasks/{}".format(tid))

def check(tid):
"""Check status of the scheduled task"""
Expand Down
3 changes: 3 additions & 0 deletions cvat/apps/engine/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
path( # GET, DELETE, PATCH
REST_API_PREFIX + 'tasks/<int:pk>', views.TaskDetail.as_view(),
name='task-detail'),
path( # PUT
REST_API_PREFIX + 'tasks/<int:pk>/data/', views.TaskDetail.as_view(),
name='task-data'),
path( # GET
REST_API_PREFIX + 'tasks/<int:pk>/status', views.TaskStatus.as_view(),
name='task-status'),
Expand Down
4 changes: 3 additions & 1 deletion cvat/apps/engine/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def perform_create(self, serializer):
serializer.save()
else:
serializer.save(owner=self.request.user)
tid = serializer.data["id"]
task.create(tid, serializer.data)

class TaskDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = Task.objects.all()
Expand All @@ -69,7 +71,7 @@ class TaskStatus(APIView):
def get(self, request, version, pk):
db_task = get_object_or_404(Task, pk=pk)
response = self._get_response(queue="default",
job_id="api/{}/tasks/{}".format(version, pk))
job_id="/api/{}/tasks/{}".format(version, pk))
serializer = TaskStatus.serializer_class(data=response)

if serializer.is_valid(raise_exception=True):
Expand Down

0 comments on commit 4feb191

Please sign in to comment.