diff --git a/notebooker/serialization/mongo.py b/notebooker/serialization/mongo.py index 4ddf97b2..73f696e4 100644 --- a/notebooker/serialization/mongo.py +++ b/notebooker/serialization/mongo.py @@ -535,6 +535,10 @@ def delete_result(self, job_id: AnyStr) -> Dict[str, Any]: self.result_data_store.delete(filename) return {"deleted_result_document": result, "gridfs_filenames": gridfs_filenames} + def delete_all_for_report_name(self, report_name: AnyStr) -> Dict[str, Any]: + results = self.get_all_result_keys(mongo_filter={"report_name": report_name}) + return {job_id: self.delete_result(job_id) for _, job_id in results} + def _pdf_filename(job_id: str) -> str: return f"{job_id}.pdf" diff --git a/notebooker/web/routes/report_execution.py b/notebooker/web/routes/report_execution.py index d837a17c..f95ab789 100644 --- a/notebooker/web/routes/report_execution.py +++ b/notebooker/web/routes/report_execution.py @@ -7,7 +7,7 @@ from typing import Any, Dict, List, Tuple, NamedTuple, Optional, AnyStr import nbformat -from flask import Blueprint, abort, jsonify, render_template, request, url_for, current_app +from flask import Blueprint, abort, jsonify, render_template, request, url_for, current_app, redirect from nbformat import NotebookNode from notebooker.constants import DEFAULT_RESULT_LIMIT @@ -300,3 +300,23 @@ def delete_report(job_id): except Exception: error_info = traceback.format_exc() return jsonify({"status": "error", "error": error_info}), 500 + + +@run_report_bp.route("/delete_all_reports/", methods=["GET", "POST"]) +def delete_all_reports(report_name): + """ + Deletes all reports associated with a particular report_name from the underlying storage. + Only marks as "status=deleted" so the report is retrievable at a later date. + + :param report_name: The parameter here should be a "/"-delimited string which mirrors the directory structure of \ + the notebook templates. + + :return: A JSON which contains "status" which will either be "ok" or "error". + """ + try: + get_serializer().delete_all_for_report_name(report_name) + get_all_result_keys(get_serializer(), limit=DEFAULT_RESULT_LIMIT, force_reload=True) + return redirect("/") + except Exception: + error_info = traceback.format_exc() + return jsonify({"status": "error", "error": error_info}), 500 diff --git a/notebooker/web/templates/result_listing.html b/notebooker/web/templates/result_listing.html index c2360052..1fa4e2e9 100644 --- a/notebooker/web/templates/result_listing.html +++ b/notebooker/web/templates/result_listing.html @@ -38,10 +38,13 @@

{{ titleised_report_name }} ({{ report_name {% endif %} {% if not readonly_mode %} -
- +
+ Manually run this report +
{% endif %}
@@ -56,5 +59,74 @@

{{ titleised_report_name }} ({{ report_name
Cancel
+ + + + + +