]> git.parisson.com Git - teleforma.git/commitdiff
add XsSharing middleware (external JSON call), add media listing RPC
authorGuillaume Pellerin <yomguy@parisson.com>
Mon, 16 Sep 2013 11:03:18 +0000 (13:03 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Mon, 16 Sep 2013 11:03:18 +0000 (13:03 +0200)
teleforma/middleware.py
teleforma/views/core.py

index 628eff301c00fd8f824e9748d058d4239fb96695..143cf9284ce0db73ce0eb16c5d348a754cc5df94 100644 (file)
@@ -40,3 +40,51 @@ class ItemExportSecurity(object):
         else:
             return None
                 
+import re
+from django.utils.text import compress_string
+from django.utils.cache import patch_vary_headers
+from django import http
+try:
+    import settings 
+    XS_SHARING_ALLOWED_ORIGINS = settings.XS_SHARING_ALLOWED_ORIGINS
+    XS_SHARING_ALLOWED_METHODS = settings.XS_SHARING_ALLOWED_METHODS
+    XS_SHARING_ALLOWED_HEADERS = settings.XS_SHARING_ALLOWED_HEADERS
+except:
+    XS_SHARING_ALLOWED_ORIGINS = '*'
+    XS_SHARING_ALLOWED_METHODS = ['POST','GET','OPTIONS', 'PUT', 'DELETE']
+    XS_SHARING_ALLOWED_HEADERS = ['Origin', 'Content-Type', 'Accept']
+class XsSharing(object):
+    """
+        This middleware allows cross-domain XHR using the html5 postMessage API.
+         
+        Access-Control-Allow-Origin: http://foo.example
+        Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE
+    """
+    def process_request(self, request):
+        if 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' in request.META:
+            response = http.HttpResponse()
+            response['Access-Control-Allow-Origin']  = XS_SHARING_ALLOWED_ORIGINS 
+            response['Access-Control-Allow-Methods'] = ",".join( XS_SHARING_ALLOWED_METHODS ) 
+            response['Access-Control-Allow-Headers'] = ",".join( XS_SHARING_ALLOWED_HEADERS ) 
+            
+            return response
+        return None
+    def process_response(self, request, response):
+        # Avoid unnecessary work
+        if response.has_header('Access-Control-Allow-Origin'):
+            return response
+        response['Access-Control-Allow-Origin']  = XS_SHARING_ALLOWED_ORIGINS 
+        response['Access-Control-Allow-Methods'] = ",".join( XS_SHARING_ALLOWED_METHODS )
+        response['Access-Control-Allow-Headers'] = ",".join( XS_SHARING_ALLOWED_HEADERS ) 
+        return response
index 791dac5a6966bd69fe5e3c7923f7218ce414ccb3..029e43b19a7da8d1e6bd969d8d08ba58db5573a2 100644 (file)
@@ -293,6 +293,17 @@ class CourseView(CourseAccessMixin, DetailView):
     def dispatch(self, *args, **kwargs):
         return super(CourseView, self).dispatch(*args, **kwargs)
 
+    @jsonrpc_method('teleforma.get_course_media_urls')
+    def get_course_media_urls(request, id):
+        course = Course.objects.get(public_id=id)
+        media_list = []
+        for media in course.media.all():
+            urls = [ {'url': settings.MEDIA_URL + unicode(media.item.file), 'mime_type': media.mime_type} ]
+            for transcoded in media.item.transcoded.all():
+                urls.append({'url':settings.MEDIA_URL + unicode(transcoded.file), 'mime_type': media.mime_type})
+            media_list.append({'session': media.conference.session, 'urls': urls})
+        return media_list
+
 
 class MediaView(CourseAccessMixin, DetailView):