From 4beef23e2f554b0a290a2f913b87c05507a981fe Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Wed, 22 Dec 2021 12:41:21 +0300 Subject: Add interface for displaying diffs in a html page --- wqflask/wqflask/metadata_edits.py | 10 ++- wqflask/wqflask/templates/display_diffs.html | 96 ++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 wqflask/wqflask/templates/display_diffs.html diff --git a/wqflask/wqflask/metadata_edits.py b/wqflask/wqflask/metadata_edits.py index fa6cfea3..593605b5 100644 --- a/wqflask/wqflask/metadata_edits.py +++ b/wqflask/wqflask/metadata_edits.py @@ -440,7 +440,14 @@ def show_diff(name): with open(os.path.join(f"{TMPDIR}/sample-data/diffs", name), 'r') as myfile: content = myfile.read() - return Response(content, mimetype='text/json') + content = json.loads(content) + for data in content.get("Modifications"): + data["Diff"] = "\n".join(difflib.ndiff([data.get("Original")], + [data.get("Current")])) + return render_template( + "display_diffs.html", + diff=content + ) @metadata_edit.route("/diffs//reject") @@ -465,6 +472,7 @@ def approve_data(resource_id:str, file_name: str): passwd=current_app.config.get("DB_PASS"), host=current_app.config.get("DB_HOST")) TMPDIR = current_app.config.get("TMPDIR") + import pudb; pu.db with open(os.path.join(f"{TMPDIR}/sample-data/diffs", file_name), 'r') as myfile: sample_data = json.load(myfile) diff --git a/wqflask/wqflask/templates/display_diffs.html b/wqflask/wqflask/templates/display_diffs.html new file mode 100644 index 00000000..edd889b5 --- /dev/null +++ b/wqflask/wqflask/templates/display_diffs.html @@ -0,0 +1,96 @@ +{% extends "base.html" %} +{% block title %}Trait Submission{% endblock %} + +{% block css %} + +{% endblock %} + +{% block content %} + +
+ {% set additions = diff.get("Additions") %} + {% set modifications = diff.get("Modifications") %} + {% set deletions = diff.get("Deletions") %} + + {% if additions %} +

Additions Data:

+
+
+ + + + + {% for data in additions %} + + + + {% endfor %} + +
Added Data +
{{ data }}
+
+
+ {% endif %} + + {% if modifications %} +

Modified Data:

+ +
+
+ + + + + {% for data in modifications %} + + + + + + {% endfor %} + +
Original + Current + Diff +
{{ data.get("Original") }}{{ data.get("Current") }}
{{data.get("Diff")}}
+
+
+ {% endif %} + + {% if deletions %} +

Deleted Data:

+
+
+ + + + + {% for data in deletions %} + + + + {% endfor %} + +
Deleted Data +
{{ data }}
+
+
+ {% endif %} + +
+{%endblock%} + +{% block js %} + + + +{% endblock %} -- cgit v1.2.3