Coverage for application / image_review / tator / routes.py: 17%
48 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-23 05:22 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-23 05:22 +0000
1"""
2Tator-specific image review endpoint.
4/image-review/tator [GET]
5"""
6import json
8import tator
9import requests
10from flask import current_app, flash, render_template, redirect, request, session
12from . import tator_image_review_bp
13from application.tator.tator_localization_processor import TatorLocalizationProcessor
16# view all Tator annotations (localizations) in a specified project & section
17@tator_image_review_bp.get('')
18def tator_image_review():
19 if 'tator_token' not in session.keys():
20 return redirect('/')
21 if not request.args.get('project') or not request.args.getlist('section'):
22 flash('Please select a project and a section', 'info')
23 return redirect('/')
24 project_id = int(request.args.get('project'))
25 section_ids = request.args.getlist('section')
26 transect_ids = request.args.getlist('transect')
27 try:
28 api = tator.get_api(
29 host=current_app.config.get('TATOR_URL'),
30 token=session['tator_token'],
31 )
32 localization_processor = TatorLocalizationProcessor(
33 project_id=project_id,
34 section_ids=section_ids,
35 api=api,
36 tator_url=current_app.config.get('TATOR_URL'),
37 transect_media_ids=(int(transect_id) for transect_id in transect_ids) if transect_ids else None,
38 )
39 localization_processor.fetch_localizations()
40 localization_processor.process_records()
41 except tator.openapi.tator_openapi.exceptions.ApiException as e:
42 flash(json.loads(e.body)['message'], 'danger')
43 return redirect('/')
44 comments = {}
45 image_refs = {}
46 # get comments and image ref list from external review db
47 try:
48 for section in localization_processor.sections:
49 comment_res = requests.get(
50 url=f'{current_app.config.get("DARC_REVIEW_URL")}/comment/sequence/{section.deployment_name.replace("-", "_")}',
51 headers=current_app.config.get('DARC_REVIEW_HEADERS'),
52 )
53 if comment_res.status_code != 200:
54 raise requests.exceptions.ConnectionError
55 comments |= comment_res.json() # merge dicts
56 image_ref_res = requests.get(f'{current_app.config.get("DARC_REVIEW_URL")}/image-reference/quick')
57 if image_ref_res.status_code != 200:
58 raise requests.exceptions.ConnectionError
59 image_refs = image_ref_res.json()
60 except requests.exceptions.ConnectionError:
61 print('\nERROR: unable to connect to external review server\n')
62 expedition_name = localization_processor.sections[0].expedition_name
63 if transect_ids:
64 transect_media = api.get_media_list(project_id, media_id=[int(tid) for tid in transect_ids])
65 transect_names = [media.name for media in transect_media]
66 deployments_str = ', '.join(transect_names)
67 tab_title = transect_names[0] if len(transect_names) == 1 else expedition_name
68 else:
69 deployments_str = ', '.join([section.deployment_name for section in localization_processor.sections])
70 tab_title = localization_processor.sections[0].deployment_name if len(localization_processor.sections) == 1 else expedition_name
71 data = {
72 'annotations': localization_processor.final_records,
73 'title': expedition_name,
74 'tab_title': tab_title,
75 'deployments': deployments_str,
76 'concepts': session.get('vars_concepts', []),
77 'reviewers': session.get('reviewers', []),
78 'comments': comments,
79 'image_refs': image_refs,
80 }
81 return render_template('image_review/image-review.html', data=data)