@@ -27,10 +27,10 @@ def {method_name}(jwt_payload: dict) -> dict:
2727 djconn = _DJConnector._set_datajoint_config(jwt_payload)
2828 vm_list = [dj.VirtualModule(s, s, connection=djconn)
2929 for s in inspect.getfullargspec(dj_query).args]
30- query, fetch_args = dj_query(*vm_list)
31- query = query & restriction()
30+ djdict = dj_query(*vm_list)
31+ djdict[' query'] = djdict[' query'] & restriction()
3232 record_header, table_tuples, total_count = _DJConnector._fetch_records(
33- query=query,
33+ query=djdict[' query'], fetch_args=djdict['fetch_args'] ,
3434 **{{k: (int(v) if k in ('limit', 'page')
3535 else (v.split(',') if k == 'order'
3636 else loads(b64decode(v.encode('utf-8')).decode('utf-8'))))
@@ -52,15 +52,37 @@ def {method_name}_attributes(jwt_payload: dict) -> dict:
5252 djconn = _DJConnector._set_datajoint_config(jwt_payload)
5353 vm_list = [dj.VirtualModule(s, s, connection=djconn)
5454 for s in inspect.getfullargspec(dj_query).args]
55- query, fetch_args = dj_query(*vm_list)
56- attributes_meta = _DJConnector._get_attributes(query)
55+ djdict = dj_query(*vm_list)
56+ attributes_meta = _DJConnector._get_attributes(djdict[' query'] )
5757
5858 return dict(attributeHeaders=attributes_meta['attribute_headers'],
5959 attributes=attributes_meta['attributes'])
6060 except Exception as e:
6161 return str(e), 500
6262"""
6363
64+ plot_route_template = '''
65+
66+ @app.route('{route}', methods=['GET'])
67+ @protected_route
68+ def {method_name}(jwt_payload: dict) -> dict:
69+
70+ {query}
71+ {restriction}
72+ if request.method in {{'GET'}}:
73+ try:
74+ djconn = _DJConnector._set_datajoint_config(jwt_payload)
75+ vm_list = [dj.VirtualModule(s, s, connection=djconn)
76+ for s in inspect.getfullargspec(dj_query).args]
77+ djdict = dj_query(*vm_list)
78+ djdict['query'] = djdict['query'] & restriction()
79+ record_header, table_tuples, total_count = _DJConnector._fetch_records(
80+ fetch_args=djdict['fetch_args'], query=djdict['query'], fetch_blobs=True)
81+ return dict(table_tuples[0][0])
82+ except Exception as e:
83+ return str(e), 500
84+ '''
85+
6486 pharus_root = f"{ pkg_resources .get_distribution ('pharus' ).module_path } /pharus"
6587 api_path = f'{ pharus_root } /dynamic_api.py'
6688 spec_path = os .environ .get ('API_SPEC_PATH' )
@@ -79,3 +101,8 @@ def {method_name}_attributes(jwt_payload: dict) -> dict:
79101 method_name = comp ['route' ].replace ('/' , '' ),
80102 query = indent (comp ['dj_query' ], ' ' ),
81103 restriction = indent (comp ['restriction' ], ' ' )))
104+ if comp ['type' ] == 'plot:plotly:stored_json' :
105+ f .write (plot_route_template .format (route = comp ['route' ],
106+ method_name = comp ['route' ].replace ('/' , '' ),
107+ query = indent (comp ['dj_query' ], ' ' ),
108+ restriction = indent (comp ['restriction' ], ' ' )))
0 commit comments