delete task data after delete task (#2179)

* delete task data after delete task

* fix pylint

* fix pyflakes

* fix flake8

* add test test_api_v1_tasks_delete_task_data_after_delete_task

* update change log

* pyflake fix
main
Dmitry Agapov 5 years ago committed by GitHub
parent 64f1fbbd9b
commit 59b338994d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -32,7 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed task creation from PDF (<https://github.com/opencv/cvat/pull/2141>)
- Fixed CVAT format import for frame stepped tasks (<https://github.com/openvinotoolkit/cvat/pull/2151>)
- Fixed unnecessary pyhash dependency (<https://github.com/openvinotoolkit/cvat/pull/2170>)
- Fixed Data is not getting cleared, even after deleting the Task from Django Admin App(<https://github.com/openvinotoolkit/cvat/issues/1925>)
### Security
-

@ -1,16 +1,15 @@
# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: MIT
from django.apps import AppConfig
class EngineConfig(AppConfig):
name = 'cvat.apps.engine'
def ready(self):
from django.db.models.signals import post_save
from .signals import update_task_status
post_save.connect(update_task_status, sender='engine.Job',
dispatch_uid="update_task_status")
# Required to define signals in application
import cvat.apps.engine.signals
# Required in order to silent "unused-import" in pyflake
assert cvat.apps.engine.signals

@ -1,14 +1,25 @@
# Copyright (C) 2019 Intel Corporation
#
# SPDX-License-Identifier: MIT
import shutil
from .models import Job, StatusChoice
from django.db.models.signals import post_delete, post_save
from django.dispatch import receiver
from .models import (
Data,
Job,
StatusChoice,
Task,
)
@receiver(post_save, sender=Job, dispatch_uid="update_task_status")
def update_task_status(instance, **kwargs):
db_task = instance.segment.task
db_jobs = list(Job.objects.filter(segment__task_id=db_task.id))
status = StatusChoice.COMPLETED
if list(filter(lambda x: x.status == StatusChoice.ANNOTATION, db_jobs)):
if list(filter(lambda x: x.status == StatusChoice.ANNOTATION, db_jobs)):
status = StatusChoice.ANNOTATION
elif list(filter(lambda x: x.status == StatusChoice.VALIDATION, db_jobs)):
status = StatusChoice.VALIDATION
@ -17,3 +28,12 @@ def update_task_status(instance, **kwargs):
db_task.status = status
db_task.save()
@receiver(post_delete, sender=Task, dispatch_uid="delete_task_files_on_delete_task")
def delete_task_files_on_delete_task(instance, **kwargs):
shutil.rmtree(instance.get_task_dirname(), ignore_errors=True)
@receiver(post_delete, sender=Data, dispatch_uid="delete_data_files_on_delete_data")
def delete_data_files_on_delete_data(instance, **kwargs):
shutil.rmtree(instance.get_data_dirname(), ignore_errors=True)

@ -1200,7 +1200,18 @@ class TaskDeleteAPITestCase(APITestCase):
def test_api_v1_tasks_id_no_auth(self):
self._check_api_v1_tasks_id(None)
def test_api_v1_tasks_delete_task_data_after_delete_task(self):
for task in self.tasks:
task_dir = task.get_task_dirname()
self.assertTrue(os.path.exists(task_dir))
self._check_api_v1_tasks_id(self.admin)
for task in self.tasks:
task_dir = task.get_task_dirname()
self.assertFalse(os.path.exists(task_dir))
class TaskUpdateAPITestCase(APITestCase):
def setUp(self):
self.client = APIClient()

Loading…
Cancel
Save