From 0580cb1e761b6739466b648d9d4ac6a3d13e6cd5 Mon Sep 17 00:00:00 2001 From: Yoan Le Clanche Date: Thu, 28 Jun 2018 17:23:40 +0200 Subject: [PATCH] Use the new webviewer app to display pdf --- teleforma/exam/models.py | 22 ++++++++++++++++++- .../exam/templates/exam/script_detail.html | 10 +++++++++ teleforma/urls.py | 1 + 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/teleforma/exam/models.py b/teleforma/exam/models.py index 16f4d009..9fbf6bb3 100644 --- a/teleforma/exam/models.py +++ b/teleforma/exam/models.py @@ -39,6 +39,7 @@ import os, uuid, time, hashlib, mimetypes, tempfile, datetime, urllib from django.db import models from django.contrib.auth.models import User +from django.contrib.sites.models import Site from django.db.models import Q, Max, Min from django.db.models.signals import post_save from django.conf import settings @@ -384,7 +385,26 @@ class Script(BaseResource): @property def safe_url(self): - return urllib.quote(self.url) + domain = Site.objects.get_current().domain + url = self.url + if 'pilotsystems' in domain: + url = url.replace('http://e-learning.crfpa.pre-barreau.com', '//'+domain) + + url = url.replace('http://', '//') + return urllib.quote(url) + + def unquoted_url(self): + domain = Site.objects.get_current().domain + url = self.url + if 'pilotsystems' in domain: + url = url.replace('http://e-learning.crfpa.pre-barreau.com', '//'+domain) + return url + + def has_annotations_file(self): + """ + check if an annotations file exists. Then use this file, otherwise use the new db implementation + """ + return os.path.exists(os.path.join(settings.WEBVIEWER_ANNOTATIONS_PATH, self.uuid+'.xfdf')) def box_upload(self): sleep = 10 diff --git a/teleforma/exam/templates/exam/script_detail.html b/teleforma/exam/templates/exam/script_detail.html index ac557c6c..a51087e7 100644 --- a/teleforma/exam/templates/exam/script_detail.html +++ b/teleforma/exam/templates/exam/script_detail.html @@ -2,6 +2,8 @@ {% load telemeta_utils %} {% load teleforma_tags %} {% load i18n %} +{% load static %} +{% load webviewer %} {% load thumbnail %} {% block extra_javascript %} @@ -9,6 +11,8 @@ + + + + {% endblock extra_javascript %} {% block content %} @@ -123,8 +129,12 @@

+ {% if script.has_annotations_file %} + {% else %} + {% webviewer url=script.unquoted_url uuid=script.uuid %} + {% endif %}
diff --git a/teleforma/urls.py b/teleforma/urls.py index 02e99a06..b5eb3748 100644 --- a/teleforma/urls.py +++ b/teleforma/urls.py @@ -139,4 +139,5 @@ urlpatterns = patterns('', # EXAM url(r'^', include('teleforma.exam.urls')), + ) -- 2.39.5