/
vshmidt
/
label-studio
Обзор
Документация
Войти
/
vshmidt
/
label-studio
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
label_studio/labels_manager/functions.py
34 строки
1 KB
Jo Booth
feat: LSDV-5479: add blue to build and pre commit (#4750)
14 сен 2023, 01:11
Не верифицирован
14 сен 2023, 01:11
fe0326c
Код
Авторство
О чём код?
from django.db import transaction from tasks.models import Annotation def bulk_update_label(old_label, new_label, organization, project=None): annotations = Annotation.objects.filter(project__organization=organization) if project is not None: annotations = annotations.filter(project=project) updated_count = 0 with transaction.atomic(): update_annotations = [] for annotation in annotations.only('result').all(): result = annotation.result updated_result = [] need_update = False for region in result: result_type = region.get('type') if result_type is not None: label = region['value'].get(result_type) if label is not None and label == old_label: region['value'][result_type] = new_label updated_count += 1 need_update = True updated_result.append(region) if need_update: annotation.result = updated_result update_annotations.append(annotation) if update_annotations: Annotation.objects.bulk_update(update_annotations, ['result']) return updated_count