From ae4c847cbf662439af3d0dcb4108bd87e5f46f75 Mon Sep 17 00:00:00 2001
From: FSMPI Admin-Team <admin@fsmpi.rwth-aachen.de>
Date: Mon, 3 Apr 2017 19:03:24 +0200
Subject: [PATCH] Use cached etherpad url

---
 models/database.py | 2 ++
 tasks.py           | 3 ++-
 utils.py           | 5 ++++-
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/models/database.py b/models/database.py
index 8056820..f59b24d 100644
--- a/models/database.py
+++ b/models/database.py
@@ -219,6 +219,8 @@ class Protocol(DatabaseModel):
         return self.done
 
     def get_identifier(self):
+        if self.pad_identifier is not None:
+            return self.pad_identifier
         if self.date is None:
             return None
         return "{}-{}".format(
diff --git a/tasks.py b/tasks.py
index f08ea29..14f99ed 100644
--- a/tasks.py
+++ b/tasks.py
@@ -582,5 +582,6 @@ def set_etherpad_content(protocol):
 def set_etherpad_content_async(protocol_id):
     with app.app_context():
         protocol = Protocol.query.filter_by(id=protocol_id).first()
-        set_etherpad_text(protocol.get_identifier(), protocol.get_template())
+        identifier = protocol.get_identifier()
+        return set_etherpad_text(identifier, protocol.get_template())
     
diff --git a/utils.py b/utils.py
index 22917b0..d4ce449 100644
--- a/utils.py
+++ b/utils.py
@@ -120,13 +120,16 @@ def get_etherpad_text(pad):
     return req.text
 
 def set_etherpad_text(pad, text, only_if_default=True):
+    print(pad)
     if only_if_default:
         current_text = get_etherpad_text(pad)
         if current_text != config.EMPTY_ETHERPAD and len(current_text.strip()) > 0:
             return False
     file_like = BytesIO(text.encode("utf-8"))
     files = {"file": file_like}
-    req = requests.post(get_etherpad_import_url(pad), files=files)
+    url = get_etherpad_import_url(pad)
+    print(url)
+    req = requests.post(url, files=files)
     return req.status_code == 200
     
 def split_terms(text, quote_chars="\"'", separators=" \t\n"):
-- 
GitLab