Coverage for application / image_review / tator / routes.py: 18%

39 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-07 06:46 +0000

1""" 

2Tator-specific image review endpoint. 

3 

4/image-review/tator [GET] 

5""" 

6 

7import tator 

8import requests 

9from flask import current_app, flash, render_template, redirect, request, session 

10 

11from . import tator_image_review_bp 

12from application.image_review.tator.tator_localization_processor import TatorLocalizationProcessor 

13 

14 

15# view all Tator annotations (localizations) in a specified project & section 

16@tator_image_review_bp.get('') 

17def tator_image_review(): 

18 if 'tator_token' not in session.keys(): 

19 return redirect('/') 

20 if not request.args.get('project') or not request.args.getlist('section'): 

21 flash('Please select a project and a section', 'info') 

22 return redirect('/') 

23 project_id = int(request.args.get('project')) 

24 section_ids = request.args.getlist('section') 

25 try: 

26 api = tator.get_api( 

27 host=current_app.config.get('TATOR_URL'), 

28 token=session['tator_token'], 

29 ) 

30 localization_processor = TatorLocalizationProcessor( 

31 project_id=project_id, 

32 section_ids=section_ids, 

33 api=api, 

34 tator_url=current_app.config.get('TATOR_URL'), 

35 ) 

36 localization_processor.fetch_localizations() 

37 localization_processor.load_phylogeny() 

38 localization_processor.process_records() 

39 except tator.openapi.tator_openapi.exceptions.ApiException: 

40 flash('Please log in to Tator', 'info') 

41 return redirect('/') 

42 comments = {} 

43 image_refs = {} 

44 # get comments and image ref list from external review db 

45 try: 

46 for section in localization_processor.sections: 

47 comment_res = requests.get( 

48 url=f'{current_app.config.get("DARC_REVIEW_URL")}/comment/sequence/{section.deployment_name.replace("-", "_")}', 

49 headers=current_app.config.get('DARC_REVIEW_HEADERS'), 

50 ) 

51 if comment_res.status_code != 200: 

52 raise requests.exceptions.ConnectionError 

53 comments |= comment_res.json() # merge dicts 

54 image_ref_res = requests.get(f'{current_app.config.get("DARC_REVIEW_URL")}/image-reference/quick') 

55 if image_ref_res.status_code != 200: 

56 raise requests.exceptions.ConnectionError 

57 image_refs = image_ref_res.json() 

58 except requests.exceptions.ConnectionError: 

59 print('\nERROR: unable to connect to external review server\n') 

60 data = { 

61 'annotations': localization_processor.final_records, 

62 'title': localization_processor.sections[0].expedition_name, 

63 'tab_title': localization_processor.sections[0].deployment_name if len(localization_processor.sections) == 1 else f'{localization_processor.sections[0].expedition_name}', 

64 'deployments': ', '.join([section.deployment_name for section in localization_processor.sections]), 

65 'concepts': session.get('vars_concepts', []), 

66 'reviewers': session.get('reviewers', []), 

67 'comments': comments, 

68 'image_refs': image_refs, 

69 } 

70 return render_template('image_review/image-review.html', data=data)