diff --git a/label_studio/data_manager/actions/basic.py b/label_studio/data_manager/actions/basic.py index 42676390c73a..b5a48db928c8 100644 --- a/label_studio/data_manager/actions/basic.py +++ b/label_studio/data_manager/actions/basic.py @@ -63,6 +63,9 @@ def delete_tasks(project, queryset, **kwargs): project.views.all().delete() reload = True + # Execute actions after delete tasks + Task.after_bulk_delete_actions(tasks_ids_list) + return {'processed_items': count, 'reload': reload, 'detail': 'Deleted ' + str(count) + ' tasks'} diff --git a/label_studio/tasks/mixins.py b/label_studio/tasks/mixins.py index c7b7db8d45b4..f00552cd34bd 100644 --- a/label_studio/tasks/mixins.py +++ b/label_studio/tasks/mixins.py @@ -14,6 +14,19 @@ def update_is_labeled(self, *args, **kwargs) -> None: def post_process_bulk_update_stats(cls, tasks) -> None: pass + def before_delete_actions(self): + """ + Actions to execute before task deletion + """ + pass + + @staticmethod + def after_bulk_delete_actions(tasks_ids): + """ + Actions to execute after bulk task deletion + """ + pass + class AnnotationMixin: def has_permission(self, user: 'User') -> bool: # noqa: F821 diff --git a/label_studio/tasks/models.py b/label_studio/tasks/models.py index 1a9e7c04f99a..3bee992b9f49 100644 --- a/label_studio/tasks/models.py +++ b/label_studio/tasks/models.py @@ -462,6 +462,12 @@ def delete_tasks_without_signals_from_task_ids(task_ids): queryset = Task.objects.filter(id__in=task_ids) Task.delete_tasks_without_signals(queryset) + def delete(self, *args, **kwargs): + self.before_delete_actions() + result = super().delete(*args, **kwargs) + # set updated_at field of task to now() + return result + pre_bulk_create = Signal(providing_args=['objs', 'batch_size']) post_bulk_create = Signal(providing_args=['objs', 'batch_size'])