33from pathlib import Path
44
55from django .template import engines
6- from nbformat .v4 import new_code_cell , new_markdown_cell
76
8- import user_templates_api . templates . jupyter_lab . utils . utils as jl_utils
9- from user_templates_api .utils .client import get_client
7+ # from nbformat.v4 import new_code_cell, new_markdown_cell
8+ # import user_templates_api.templates.jupyter_lab. utils.utils as jl_utils
109
1110
1211class JupyterLabRender :
@@ -32,54 +31,51 @@ def render(self, data):
3231 def python_generate_template_data (self , data ):
3332 return []
3433
35- def json_generate_template_data (self , data ):
36- django_engine = engines ["django" ]
37-
38- uuids = data ["uuids" ]
39- group_token = data ["group_token" ]
40-
41- util_client = get_client (group_token )
42-
43- template_json = data .get ("template" )
44- if template_json is None :
45- class_file_path = inspect .getfile (self .__class__ )
46- # Convert the string to a pathlib Path
47- class_file_path = Path (class_file_path )
48- # Grab the parent path and append template.json
49- template_file_path = class_file_path .parent / "template.json"
50- # Load that filepath since it should be the json template
51- template_json = json .load (open (template_file_path ))
52-
53- cells = []
54- for template_item in template_json :
55- cell_type = template_item ["cell_type" ]
56- src = template_item ["src" ]
57- if cell_type == "template_cell" :
58- if src == "get_metadata_cells" :
59- cells += jl_utils .get_metadata_cells (uuids , util_client )
60- elif src == "get_file_cells" :
61- cells += jl_utils .get_file_cells (uuids , util_client )
62- elif src == "get_anndata_cells" :
63- cells += jl_utils .get_anndata_cells (uuids , util_client )
64- elif cell_type == "code_cell" :
65- template = django_engine .from_string (src )
66- # Need to do something w/ the source to make sure that it has its vars replaced
67- # Have to use append here since the nbformat cell object has an add/iadd function that is really a merge
68- cells .append (new_code_cell (template .render (data )))
69- elif cell_type == "markdown_cell" :
70- template = django_engine .from_string (src )
71- # Need to do something w/ the source to make sure that it has its vars replaced
72- cells .append (new_markdown_cell (template .render (data )))
73-
74- return cells
34+ # TODO: see if this can be used without get_client
35+ # def json_generate_template_data(self, data):
36+ # django_engine = engines["django"]
37+
38+ # uuids = data["uuids"]
39+ # group_token = data["group_token"]
40+
41+ # util_client = get_client(group_token)
42+
43+ # template_json = data.get("template")
44+ # if template_json is None:
45+ # class_file_path = inspect.getfile(self.__class__)
46+ # # Convert the string to a pathlib Path
47+ # class_file_path = Path(class_file_path)
48+ # # Grab the parent path and append template.json
49+ # template_file_path = class_file_path.parent / "template.json"
50+ # # Load that filepath since it should be the json template
51+ # template_json = json.load(open(template_file_path))
52+
53+ # cells = []
54+ # for template_item in template_json:
55+ # cell_type = template_item["cell_type"]
56+ # src = template_item["src"]
57+ # if cell_type == "template_cell":
58+ # if src == "get_metadata_cells":
59+ # cells += jl_utils.get_metadata_cells(uuids, util_client)
60+ # elif src == "get_file_cells":
61+ # cells += jl_utils.get_file_cells(uuids, util_client)
62+ # elif src == "get_anndata_cells":
63+ # cells += jl_utils.get_anndata_cells(uuids, util_client)
64+ # elif cell_type == "code_cell":
65+ # template = django_engine.from_string(src)
66+ # # Need to do something w/ the source to make sure that it has its vars replaced
67+ # # Have to use append here since the nbformat cell object has an add/iadd function that is really a merge
68+ # cells.append(new_code_cell(template.render(data)))
69+ # elif cell_type == "markdown_cell":
70+ # template = django_engine.from_string(src)
71+ # # Need to do something w/ the source to make sure that it has its vars replaced
72+ # cells.append(new_markdown_cell(template.render(data)))
73+
74+ # return cells
7575
7676 def jinja_generate_template_data (self , data ):
7777 django_engine = engines ["django" ]
7878
79- group_token = data ["group_token" ]
80-
81- data ["util_client" ] = get_client (group_token )
82-
8379 # Get the file path first
8480 class_file_path = inspect .getfile (self .__class__ )
8581 # Convert the string to a pathlib Path
0 commit comments