1
1
import json
2
2
from typing import List , Optional , Mapping , Tuple
3
3
4
- from flask import Blueprint , render_template , request , jsonify , redirect , url_for
4
+ from flask import (
5
+ Blueprint ,
6
+ render_template ,
7
+ request ,
8
+ jsonify ,
9
+ redirect ,
10
+ url_for ,
11
+ current_app ,
12
+ )
5
13
from flask_jwt_extended import jwt_required
6
14
from flask_wtf import FlaskForm
7
15
from indra .statements import get_all_descendants , Statement
11
19
12
20
from indra_cogex .apps .utils import render_statements
13
21
from indra_cogex .client import Neo4jClient , autoclient
14
- from indra_cogex .client .queries import *
15
- from indra_cogex .representation import norm_id
22
+ from indra_cogex .client .queries import enrich_statements , get_statements
23
+ from indralab_auth_tools .auth import resolve_auth
24
+ from indra_cogex .representation import norm_id , indra_stmts_from_relations
16
25
17
- __all__ = ["search_blueprint" ]
18
-
19
- from indra_cogex .client .queries import enrich_statements
20
26
21
- from indra_cogex . representation import indra_stmts_from_relations
27
+ __all__ = [ "search_blueprint" ]
22
28
23
29
search_blueprint = Blueprint ("search" , __name__ , url_prefix = "/search" )
24
30
@@ -44,6 +50,8 @@ def search():
44
50
stmt_types = {c .__name__ for c in get_all_descendants (Statement )}
45
51
stmt_types -= {"Influence" , "Event" , "Unresolved" }
46
52
stmt_types_json = json .dumps (sorted (list (stmt_types )))
53
+ user , roles = resolve_auth (dict (request .args ))
54
+ remove_medscan = user is None
47
55
48
56
form = SearchForm ()
49
57
@@ -92,7 +100,7 @@ def search():
92
100
93
101
# Fetch and display statements
94
102
if agent or other_agent or rel_types :
95
- statements , evidence_count = get_statements (
103
+ statements , source_count = get_statements (
96
104
agent = agent ,
97
105
agent_role = agent_role ,
98
106
other_agent = other_agent ,
@@ -103,9 +111,18 @@ def search():
103
111
mesh_term = mesh_terms ,
104
112
limit = 1000 ,
105
113
evidence_limit = 1000 ,
106
- return_evidence_counts = True ,
114
+ return_source_counts = True ,
115
+ )
116
+ # Create evidence count from source count
117
+ evidence_count = {
118
+ k : sum (v .values ()) for k , v in source_count .items ()
119
+ }
120
+ return render_statements (
121
+ stmts = statements ,
122
+ evidence_counts = evidence_count ,
123
+ remove_medscan = remove_medscan ,
124
+ source_counts_dict = source_count ,
107
125
)
108
- return render_statements (stmts = statements , evidence_count = evidence_count )
109
126
110
127
# Render the form page
111
128
return render_template (
@@ -115,10 +132,7 @@ def search():
115
132
)
116
133
117
134
118
- from flask import current_app
119
-
120
-
121
- @search_blueprint .route ("/gilda_ground" , methods = ["GET" , "POST" ])
135
+ @search_blueprint .route ("/gilda_ground" , methods = ["POST" ])
122
136
@jwt_required (optional = True )
123
137
def gilda_ground_endpoint ():
124
138
data = request .get_json ()
0 commit comments