]> git.parisson.com Git - teleforma.git/commitdiff
Use the new webviewer app to display pdf
authorYoan Le Clanche <yoan@ellington.pilotsystems.net>
Thu, 28 Jun 2018 15:23:40 +0000 (17:23 +0200)
committerYoan Le Clanche <yoan@ellington.pilotsystems.net>
Thu, 28 Jun 2018 15:23:40 +0000 (17:23 +0200)
teleforma/exam/models.py
teleforma/exam/templates/exam/script_detail.html
teleforma/urls.py

index 16f4d009f3cca197e6024c98f228a5e002ef032c..9fbf6bb3eaac9ca71becd1fa3e9ec55390d85457 100644 (file)
@@ -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
index ac557c6c13854f5a3641ded997eed8089ffa675a..a51087e7e96caba9d37490f387cb4a9ff10147d7 100644 (file)
@@ -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 @@
   <script src="//code.jquery.com/jquery-1.10.2.js"></script>
   <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
   <script src="/static/exam/js/exam.js"></script>
+  <!--<script src='{% static "WebViewer/lib/html5/external/jquery-3.2.1.min.js" %}'></script>-->
+  <script src='{% static "WebViewer/lib/WebViewer.min.js" %}'></script>
   <script>
     // increase the default animation speed to exaggerate the effect
   {% if script.comments %}
@@ -17,6 +21,8 @@
     });
   {% endif %}
     </script>
+
+
 {% endblock extra_javascript %}
 
 {% block content %}
 <br /><br />
 <div class="media">
  <div class="script">
+  {% if script.has_annotations_file %}
     <iframe id="box-iframe" style="position:fixed; top:12%; left:0px; bottom:0px; right:0px; width:100%; height:85%; border:none; margin:0; padding:0; z-index:0;" src="{% if user.quotas.all or user.is_superuser %}{{ script_service_url }}?url={{ script.safe_url }}&username=Examinator&uuid={{ script.uuid }}{% else %}{{ script_service_url }}?url={{ script.safe_url }}&username={{ user.username }}&uuid={{ script.uuid }}{% endif %}">
     </iframe>
+  {% else %}
+    {% webviewer url=script.unquoted_url uuid=script.uuid %}
+  {% endif %}
  </div>
 </div>
 
index 02e99a064d41de83d6e070ad75d7e503a1cc8ca8..b5eb3748df62e928a6baba01d5247f0a7de3dca1 100644 (file)
@@ -139,4 +139,5 @@ urlpatterns = patterns('',
 
     # EXAM
     url(r'^', include('teleforma.exam.urls')),
+
 )