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
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()
def get_project_from_preview_file(preview_file_id): """ Get project dict of related preview file. """ preview_file = files_service.get_preview_file_raw(preview_file_id) task = Task.get(preview_file.task_id) project = Project.get(task.project_id) return project.serialize()
def get_entity_from_preview_file(preview_file_id): """ Get entity dict of related preview file. """ preview_file = files_service.get_preview_file_raw(preview_file_id) task = Task.get(preview_file.task_id) entity = Entity.get(task.entity_id) return entity.serialize()
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()
def get_comment_by_preview_file_id(preview_file_id): """ Return comment related to given preview file as a dict. """ preview_file = files_service.get_preview_file_raw(preview_file_id) comment = Comment.query.filter( Comment.previews.contains(preview_file)).first() if comment is not None: return comment.serialize() else: return None
def update_preview_file_annotations(project_id, preview_file_id, annotations): """ Update annotations for given preview file. """ preview_file = files_service.get_preview_file_raw(preview_file_id) preview_file.update({"annotations": annotations}) events.emit( "preview-file:annotation-update", {"preview_file_id": preview_file_id}, project_id=project_id, ) return {"id": preview_file_id}
def update_preview_file_position(preview_file_id, position): """ Change positions for preview files of given task and revision. Given position is the new position for given preview file. :q """ preview_file = files_service.get_preview_file_raw(preview_file_id) task_id = preview_file.task_id revision = preview_file.revision preview_files = (PreviewFile.query.filter_by( task_id=task_id, revision=revision).order_by(PreviewFile.position, PreviewFile.created_at).all()) if position > 0 and position <= len(preview_files): tmp_list = [p for p in preview_files if str(p.id) != preview_file_id] tmp_list.insert(position - 1, preview_file) for (i, preview) in enumerate(tmp_list): preview.update({"position": i + 1}) return PreviewFile.serialize_list(preview_files)