From a8607ef8c50673ec486e92869b4632fb601cf1ef Mon Sep 17 00:00:00 2001
From: Robin Sonnabend <robin@fsmpi.rwth-aachen.de>
Date: Thu, 9 Mar 2017 04:09:48 +0100
Subject: [PATCH] Show warning on push to etherpad

If the protocol is not on the same day, show a warning before pushing
the template to the etherpad. #44
---
 server.py                    | 5 ++++-
 templates/protocol-show.html | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/server.py b/server.py
index b75ec3f..d88bd31 100755
--- a/server.py
+++ b/server.py
@@ -475,7 +475,10 @@ def show_protocol(protocol):
     documents_table = DocumentsTable(visible_documents)
     document_upload_form = DocumentUploadForm()
     source_upload_form = KnownProtocolSourceUploadForm()
-    return render_template("protocol-show.html", protocol=protocol, errors_table=errors_table, documents_table=documents_table, document_upload_form=document_upload_form, source_upload_form=source_upload_form)
+    time_diff = protocol.date - datetime.now().date()
+    print(time_diff)
+    large_time_diff = not protocol.is_done() and time_diff.days > 0
+    return render_template("protocol-show.html", protocol=protocol, errors_table=errors_table, documents_table=documents_table, document_upload_form=document_upload_form, source_upload_form=source_upload_form, time_diff=time_diff, large_time_diff=large_time_diff)
 
 @app.route("/protocol/delete/<int:protocol_id>")
 @login_required
diff --git a/templates/protocol-show.html b/templates/protocol-show.html
index 47d116b..9673b8e 100644
--- a/templates/protocol-show.html
+++ b/templates/protocol-show.html
@@ -23,7 +23,7 @@
                 {% endif %} 
                 <a class="btn {% if protocol.is_done() %}btn-success{% else %}btn-default{% endif %}" href="{{url_for("update_protocol", protocol_id=protocol.id)}}">Editieren</a>
                 {% if config.ETHERPAD_ACTIVE %}
-                <a class="btn btn-primary" href="{{url_for("etherpush_protocol", protocol_id=protocol.id)}}">Etherpad</a>
+                <a class="btn btn-primary" href="{{url_for("etherpush_protocol", protocol_id=protocol.id)}}"{% if large_time_diff %} onclick="return confirm('Bist du dir sicher, dass du das Template bereits in das Etherpad kopieren willst? Die Sitzung ist erst in {{time_diff.days}} Tagen.');"{% endif %}>Etherpad</a>
                 {% endif %}
                 {% if not protocol.is_done() %}
                     <a class="btn btn-default" href="{{url_for("get_protocol_template", protocol_id=protocol.id)}}">Vorlage</a>
-- 
GitLab