def api_all_tasks(): """ Tasks API: retrieve by filters, delete all tasks """ from label_studio.data_manager.functions import prepare_tasks # retrieve tasks (plus completions and predictions) with pagination & ordering if request.method == 'GET': tab = { 'ordering': [request.values.get('order', 'id')], 'filters': request.json.get('filters', None) if request.json is not None else None, 'fields': request.values.get('fields', 'all').split(',') } # get filter parameters from request page, page_size = int(request.values.get('page', 1)), int( request.values.get('page_size', 10)) if page < 1 or page_size < 1: return make_response({'detail': 'Incorrect page or page_size'}, 422) params = SimpleNamespace(page=page, page_size=page_size, tab=tab, resolve_uri=True) tasks = prepare_tasks(g.project, params) return make_response(jsonify(tasks), 200) # delete all tasks with completions if request.method == 'DELETE': g.project.delete_all_tasks() return make_response(jsonify({'detail': 'deleted'}), 204)
def api_project_tab_tasks(tab_id): """ Get tasks for specified tab """ tab_id = int(tab_id) tab = load_tab(tab_id, g.project, raise_if_not_exists=True) # get pagination page, page_size = int(request.values.get('page', 1)), int( request.values.get('page_size', 10)) if page < 1 or page_size < 1: return make_response( jsonify({'detail': 'Incorrect page or page_size'}), 422) params = SimpleNamespace(page=page, page_size=page_size, tab=tab, resolve_uri=True) tasks = prepare_tasks(g.project, params) return make_response(jsonify(tasks), 200)
def api_project_tab_annotations(tab_id): """ Get annotations for specified tab """ tab_id = int(tab_id) tab = load_tab(tab_id, g.project, raise_if_not_exists=True) page, page_size = int(request.values.get('page', 1)), int( request.values.get('page_size', 10)) if page < 1 or page_size < 1: return make_response( jsonify({'detail': 'Incorrect page or page_size'}), 422) # get tasks first task_params = SimpleNamespace(page=0, page_size=0, tab=tab) # take all tasks from tab tasks = prepare_tasks(g.project, task_params) # pass tasks to get annotation over them annotation_params = SimpleNamespace(page=page, page_size=page_size, tab=tab) annotations = prepare_annotations(tasks['tasks'], annotation_params) return make_response(jsonify(annotations), 200)