Loading api_templates.py +10 −5 Original line number Diff line number Diff line Loading @@ -90,13 +90,19 @@ def import_scan2report_templates_to_pwndoc(): FlashLog.error(error_msg) return redirect(url_for('api_templates.import_scan2report_templates_to_pwndoc')) PwndocTemplateManager.update_template_db_from_pwndoc() # necessary for mapping new uploads to existing templates saved_filepaths = [os.path.join(output_folder, x) for x in saved_filenames] upload_scan2report_templates(locale_to_import, saved_filepaths) return redirect(url_for('api_templates.import_scan2report_templates_to_pwndoc')) def upload_scan2report_templates(locale_to_import: str, saved_filepaths: List[str]): PwndocTemplateManager.update_template_db_from_pwndoc() # necessary for mapping new uploads to existing templates bundled_templates: Dict[str, Dict[str, TNSTemplatePwndoc]] = defaultdict(dict) for single_filename in tqdm(saved_filenames, desc="Converting templates"): for single_filepath in tqdm(saved_filepaths, desc="Converting templates"): single_filename = os.path.basename(single_filepath) fid = extract_fid_from_filename(single_filename) with open(os.path.join(output_folder, single_filename), encoding="utf8") as f: with open(single_filepath, encoding="utf8") as f: template_json = json.load(f) lang_and_templates: Dict[str, TemplateScan2Report] = TemplateScan2Report.parse_dict_for_locale_and_og(fid, locale_to_import, template_json) # I don't need to do DB refresh (for pwndoc ID) after every addition because I'm processing only single locale (or locale and og at the same time). Loading @@ -105,7 +111,7 @@ def import_scan2report_templates_to_pwndoc(): assert fid == single_tns_template.fid assert locale == single_tns_template.locale bundled_templates[fid][locale] = single_tns_template del single_filename, fid, single_tns_template, locale, template_json, lang_and_templates, f, output_folder del single_filename, fid, single_tns_template, locale, template_json, lang_and_templates, f for fid in tqdm(bundled_templates, desc="Uploading templates"): dict_of_locales: Dict[str, TNSTemplatePwndoc] = bundled_templates[fid] Loading @@ -114,7 +120,6 @@ def import_scan2report_templates_to_pwndoc(): PwndocTemplateManager.update_template_db_from_pwndoc() # todo: this is workaround for not using PwndocTemplateManager.add_single_locale_template FlashLog.info(f"OK; {len(bundled_templates)} templates uploaded") return redirect(url_for('api_templates.import_scan2report_templates_to_pwndoc')) @bp.route("/export_as_scan2report_native", methods=["GET"]) Loading Loading
api_templates.py +10 −5 Original line number Diff line number Diff line Loading @@ -90,13 +90,19 @@ def import_scan2report_templates_to_pwndoc(): FlashLog.error(error_msg) return redirect(url_for('api_templates.import_scan2report_templates_to_pwndoc')) PwndocTemplateManager.update_template_db_from_pwndoc() # necessary for mapping new uploads to existing templates saved_filepaths = [os.path.join(output_folder, x) for x in saved_filenames] upload_scan2report_templates(locale_to_import, saved_filepaths) return redirect(url_for('api_templates.import_scan2report_templates_to_pwndoc')) def upload_scan2report_templates(locale_to_import: str, saved_filepaths: List[str]): PwndocTemplateManager.update_template_db_from_pwndoc() # necessary for mapping new uploads to existing templates bundled_templates: Dict[str, Dict[str, TNSTemplatePwndoc]] = defaultdict(dict) for single_filename in tqdm(saved_filenames, desc="Converting templates"): for single_filepath in tqdm(saved_filepaths, desc="Converting templates"): single_filename = os.path.basename(single_filepath) fid = extract_fid_from_filename(single_filename) with open(os.path.join(output_folder, single_filename), encoding="utf8") as f: with open(single_filepath, encoding="utf8") as f: template_json = json.load(f) lang_and_templates: Dict[str, TemplateScan2Report] = TemplateScan2Report.parse_dict_for_locale_and_og(fid, locale_to_import, template_json) # I don't need to do DB refresh (for pwndoc ID) after every addition because I'm processing only single locale (or locale and og at the same time). Loading @@ -105,7 +111,7 @@ def import_scan2report_templates_to_pwndoc(): assert fid == single_tns_template.fid assert locale == single_tns_template.locale bundled_templates[fid][locale] = single_tns_template del single_filename, fid, single_tns_template, locale, template_json, lang_and_templates, f, output_folder del single_filename, fid, single_tns_template, locale, template_json, lang_and_templates, f for fid in tqdm(bundled_templates, desc="Uploading templates"): dict_of_locales: Dict[str, TNSTemplatePwndoc] = bundled_templates[fid] Loading @@ -114,7 +120,6 @@ def import_scan2report_templates_to_pwndoc(): PwndocTemplateManager.update_template_db_from_pwndoc() # todo: this is workaround for not using PwndocTemplateManager.add_single_locale_template FlashLog.info(f"OK; {len(bundled_templates)} templates uploaded") return redirect(url_for('api_templates.import_scan2report_templates_to_pwndoc')) @bp.route("/export_as_scan2report_native", methods=["GET"]) Loading