Esempio n. 1
0
def update_preview_file_annotations(person_id,
                                    project_id,
                                    preview_file_id,
                                    additions=[],
                                    updates=[],
                                    deletions=[]):
    """
    Update annotations for given preview file.
    """
    preview_file = files_service.get_preview_file_raw(preview_file_id)
    previous_annotations = preview_file.annotations or []
    annotations = _apply_annotation_additions(previous_annotations, additions)
    annotations = _apply_annotation_updates(annotations, updates)
    annotations = _apply_annotation_deletions(annotations, deletions)
    preview_file.update({"annotations": []})
    preview_file.update({"annotations": annotations})
    files_service.clear_preview_file_cache(preview_file_id)
    preview_file = files_service.get_preview_file(preview_file_id)
    events.emit(
        "preview-file:annotation-update",
        {
            "preview_file_id": preview_file_id,
            "person_id": person_id,
            "updated_at": preview_file["updated_at"],
        },
        project_id=project_id,
    )
    return preview_file
Esempio n. 2
0
def update_preview_file(preview_file_id, data):
    preview_file = files_service.get_preview_file_raw(preview_file_id)
    preview_file.update(data)
    files_service.clear_preview_file_cache(preview_file_id)
    task = Task.get(preview_file.task_id)
    events.emit("preview-file:update", {"preview_file_id": preview_file_id},
                project_id=str(task.project_id))
    return preview_file.serialize()
Esempio n. 3
0
def update_preview_file(preview_file_id, data, silent=False):
    try:
        preview_file = files_service.get_preview_file_raw(preview_file_id)
    except:
        # Dirty hack because sometimes the preview file retrieval crashes.
        time.sleep(1)
        preview_file = files_service.get_preview_file_raw(preview_file_id)

    preview_file.update(data)
    files_service.clear_preview_file_cache(preview_file_id)
    if not silent:
        task = Task.get(preview_file.task_id)
        events.emit(
            "preview-file:update",
            {"preview_file_id": preview_file_id},
            project_id=str(task.project_id),
        )
    return preview_file.serialize()