From 4ed026aba6add7cd710cfecbf3e4656c20719b29 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Sat, 3 Apr 2021 05:55:43 +0200 Subject: [PATCH] Re #18 - Show "preview" of the page when only one revision exists (#33) --- backend/__init__.py | 24 ++++++++++++++++++++++++ backend/templates/preview.html | 26 ++++++++++++++++++++++++++ backend/templates/watch-overview.html | 4 ++++ 3 files changed, 54 insertions(+) create mode 100644 backend/templates/preview.html diff --git a/backend/__init__.py b/backend/__init__.py index 3f6f8a3d..5574ba4f 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -405,6 +405,30 @@ def changedetection_app(config=None, datastore_o=None): return output + @app.route("/preview/", methods=['GET']) + def preview_page(uuid): + global messages + + # More for testing, possible to return the first/only + if uuid == 'first': + uuid = list(datastore.data['watching'].keys()).pop() + + extra_stylesheets = ['/static/css/diff.css'] + + try: + watch = datastore.data['watching'][uuid] + except KeyError: + messages.append({'class': 'error', 'message': "No history found for the specified link, bad link?"}) + return redirect(url_for('index')) + + print(watch) + with open(list(watch['history'].values())[-1], 'r') as f: + content = f.readlines() + + output = render_template("preview.html", content=content, extra_stylesheets=extra_stylesheets) + return output + + @app.route("/favicon.ico", methods=['GET']) def favicon(): return send_from_directory("/app/static/images", filename="favicon.ico") diff --git a/backend/templates/preview.html b/backend/templates/preview.html new file mode 100644 index 00000000..2c61e7f5 --- /dev/null +++ b/backend/templates/preview.html @@ -0,0 +1,26 @@ +{% extends 'base.html' %} + +{% block content %} + +
+

Current

+
+ + +
+ + + + + + + + + +
+ {% for row in content %}
{{row}}
{% endfor %}
+
+
+ + +{% endblock %} \ No newline at end of file diff --git a/backend/templates/watch-overview.html b/backend/templates/watch-overview.html index f29151fe..c872bfbb 100644 --- a/backend/templates/watch-overview.html +++ b/backend/templates/watch-overview.html @@ -68,6 +68,10 @@ Edit {% if watch.history|length >= 2 %} Diff + {% else %} + {% if watch.history|length == 1 %} + Preview + {% endif %} {% endif %}