acecalisto3 commited on
Commit
2a4e65c
1 Parent(s): bc76353

Update templates.py

Browse files
Files changed (1) hide show
  1. templates.py +13 -3
templates.py CHANGED
@@ -1033,8 +1033,8 @@ class TemplateManager:
1033
  )
1034
  }
1035
 
1036
- self.component_index = self._build_component_index()
1037
- self.category_index = self._build_category_index()
1038
 
1039
  def _build_component_index(self) -> Dict[str, List[str]]:
1040
  """Build index of templates by component"""
@@ -1142,6 +1142,7 @@ class TemplateManager:
1142
  try:
1143
  data = {
1144
  name: {
 
1145
  "description": template.description,
1146
  "components": template.components,
1147
  "metadata": template.metadata,
@@ -1155,6 +1156,9 @@ class TemplateManager:
1155
 
1156
  logger.info(f"Templates exported to {path}")
1157
 
 
 
 
1158
  except Exception as e:
1159
  logger.error(f"Error exporting templates: {str(e)}")
1160
  raise
@@ -1167,7 +1171,7 @@ class TemplateManager:
1167
 
1168
  for name, template_data in data.items():
1169
  self.templates[name] = Template(
1170
- code="", # Code should be loaded separately
1171
  description=template_data["description"],
1172
  components=template_data["components"],
1173
  metadata=template_data["metadata"],
@@ -1180,6 +1184,12 @@ class TemplateManager:
1180
 
1181
  logger.info(f"Templates imported from {path}")
1182
 
 
 
 
 
 
 
1183
  except Exception as e:
1184
  logger.error(f"Error importing templates: {str(e)}")
1185
  raise
 
1033
  )
1034
  }
1035
 
1036
+ self.component_index: Dict[str, List[str]] = self._build_component_index()
1037
+ self.category_index: Dict[str, List[str]] = self._build_category_index()
1038
 
1039
  def _build_component_index(self) -> Dict[str, List[str]]:
1040
  """Build index of templates by component"""
 
1142
  try:
1143
  data = {
1144
  name: {
1145
+ "code": template.code,
1146
  "description": template.description,
1147
  "components": template.components,
1148
  "metadata": template.metadata,
 
1156
 
1157
  logger.info(f"Templates exported to {path}")
1158
 
1159
+ except FileNotFoundError:
1160
+ logger.error(f"File not found: {path}")
1161
+ raise
1162
  except Exception as e:
1163
  logger.error(f"Error exporting templates: {str(e)}")
1164
  raise
 
1171
 
1172
  for name, template_data in data.items():
1173
  self.templates[name] = Template(
1174
+ code=template_data.get("code", ""), # Load the actual code from the JSON file
1175
  description=template_data["description"],
1176
  components=template_data["components"],
1177
  metadata=template_data["metadata"],
 
1184
 
1185
  logger.info(f"Templates imported from {path}")
1186
 
1187
+ except FileNotFoundError:
1188
+ logger.error(f"File not found: {path}")
1189
+ raise
1190
+ except json.JSONDecodeError:
1191
+ logger.error(f"Error decoding JSON from file: {path}")
1192
+ raise
1193
  except Exception as e:
1194
  logger.error(f"Error importing templates: {str(e)}")
1195
  raise