]> git.parisson.com Git - teleforma.git/commitdiff
set all MEDIA_URL with set_host
authoryomguy <yomguy@parisson.com>
Wed, 5 Dec 2012 18:48:16 +0000 (19:48 +0100)
committeryomguy <yomguy@parisson.com>
Wed, 5 Dec 2012 18:48:16 +0000 (19:48 +0100)
teleforma/context_processors.py
teleforma/management/commands/teleforma-export-stream-m-slugs.py [new file with mode: 0644]
teleforma/templates/teleforma/course_media.html
teleforma/templates/teleforma/inc/media_list.html

index 64aea0f4c8bce329e641d68e935897ef660fd8d3..20c2a62817388dfc62fd52ba52b4d20a3e85a7a1 100644 (file)
@@ -1,6 +1,8 @@
 # -*- coding: utf-8 -*-
 from django.conf import settings
 import socket
+import fcntl
+import struct
 
 interfaces = ['eth0', 'eth1', 'eth2', 'eth0-eth2', 'eth3', 'eth4',
                   'wlan0', 'wlan1', 'wlan2', 'wlan3', 'wlan4']
@@ -15,7 +17,7 @@ def get_ip_address(ifname):
     return ip
 
 def get_local_host():
-    local_ip = ''
+    ip = ''
     for interface in interfaces:
         try:
             ip = get_ip_address(interface)
@@ -23,12 +25,12 @@ def get_local_host():
                 local_ip = ip
                 break
         except:
-            local_ip = '127.0.0.1'    
+            local_ip = '127.0.0.1'
     return local_ip
 
 
 def get_http_host(request):
-    host = request.META['HTTP_HOST']
+    host = request.META['REMOTE_ADDR']
     if ':' in host:
         host = host.split(':')[0]
     return host
@@ -38,9 +40,6 @@ def host(request):
     request_host = get_http_host(request)
     local_host = get_local_host()
     
-    print request_host
-    print local_host
-
     if request_host.split('.')[0] == local_host.split('.')[0] or \
                                 request_host == '127.0.0.1' or request_host == 'localhost':
         # LAN access
@@ -49,4 +48,3 @@ def host(request):
         ip = settings.ROUTER_IP
 
     return {'HOST': ip }
-
diff --git a/teleforma/management/commands/teleforma-export-stream-m-slugs.py b/teleforma/management/commands/teleforma-export-stream-m-slugs.py
new file mode 100644 (file)
index 0000000..ddb4a3e
--- /dev/null
@@ -0,0 +1,53 @@
+from optparse import make_option
+from django.conf import settings
+from django.core.management.base import BaseCommand, CommandError
+from django.contrib.auth.models import User
+from django.template.defaultfilters import slugify
+from telemeta.models import *
+from telemeta.util.unaccent import unaccent
+from teleforma.models import *
+import logging
+import json
+
+class Command(BaseCommand):
+    help = "Export course slugs to a Stream-M server conf file"
+    args = "password, path"
+    admin_email = 'webmaster@parisson.com'
+    ext = 'webm'
+    data = """
+# server.bindAddress
+# example: 127.0.0.1, 192.168.1.1
+# localhost. www.example.com also work
+#server.bindAddress = 192.168.0.12
+
+# server.port
+# listening port
+server.port=8080
+
+streams.safe=true
+streams.safe.password=source2parisson
+streams.safe.limit=100
+"""
+    
+    def export(self):
+        courses = Course.objects.all()
+        types = CourseType.objects.all()
+        for course in courses:
+            for type in types:
+                slug = course.slug + '-' + type.name.lower()
+                slug = course.department.name.lower() + '-' + slug
+                self.data += '\nstreams.' + slug + '=true\n'
+                self.data += 'streams.' + slug + '.password=' + self.passwd + '\n'
+                self.data += 'streams.' + slug + '.limit=1000\n'
+
+    def handle(self, *args, **options):
+        self.passwd = args[0]
+        file = args[1]
+        self.export()
+        f = open(file, 'w')
+        f.write(self.data)
+        f.close()
+
+
+
+
index 14ede64420d006a2c652446ac620e67fbf872ba5..5c91979aa5d24d57559f61d54f72f0682db772fa 100644 (file)
@@ -59,7 +59,7 @@ $(document).ready(function(){
 {% block module-action %}
 {% if media.item.file and media.is_published %}
 <div class="module_action">
-<a href="{{ MEDIA_URL }}{{ media.item.file }}" class="component_icon button" id="action_red"><img src="{{STATIC_URL}}teleforma/images/download_media.png" alt="" style="vertical-align:middle" />&nbsp;{% trans "Download" %}</a>
+<a href="{{ MEDIA_URL|set_host:HOST }}{{ media.item.file }}" class="component_icon button" id="action_red"><img src="{{STATIC_URL}}teleforma/images/download_media.png" alt="" style="vertical-align:middle" />&nbsp;{% trans "Download" %}</a>
 </div>
 {% endif %}
 {% endblock module-action %}
@@ -95,7 +95,7 @@ $(document).ready(function(){
 <div class="video">
 <video id="my_video_1" class="video-js vjs-default-skin" width="640" height="360" controls preload="auto" data-setup='{}'>
 <!-- Hello Chrome and Firefox (and Opera?) -->
-<source src="{{ MEDIA_URL }}{{ media.item.file }}" type="{{ media.mime_type }}" />
+<source src="{{ MEDIA_URL|set_host:HOST }}{{ media.item.file }}" type="{{ media.mime_type }}" />
 </video>
 </div>
 
@@ -105,7 +105,7 @@ $(document).ready(function(){
 {% if media.item.related.all %}
  {% for related in media.item.related.all %}
   {% if related.title == "preview" %}
-   <img src="{{ MEDIA_URL }}{{ related.file }}" width="300px" alt="" />
+   <img src="{{ MEDIA_URL|set_host:HOST }}{{ related.file }}" width="300px" alt="" />
   {% endif %}
  {% endfor %}
 {% else %}
@@ -114,7 +114,7 @@ $(document).ready(function(){
 </div>
 <div class="audio">
 <audio controls preload="auto">
-<source src="{{ MEDIA_URL }}{{ media.item.file }}" type="{{ media.mime_type }}" />
+<source src="{{ MEDIA_URL|set_host:HOST }}{{ media.item.file }}" type="{{ media.mime_type }}" />
 </audio>
 </div>
 {% endif %}
index e0770566484312fc36bec913bce450f0e563d324..dea22473fdb8569ad1f4c544122158393168fd7a 100644 (file)
@@ -19,7 +19,7 @@
              {% for related in media.item.related.all %}
               {% if related.title == "preview" %}
                {% thumbnail related.file "168x96" as im %}
-                <div style="background: no-repeat url('{{ im.url }}') 0 1px; background-size: 100%; background-color: #dfdfdf;">
+                <div style="background: no-repeat url('{{ im.url|set_host:HOST }}') 0 1px; background-size: 100%; background-color: #dfdfdf;">
                  <img src="{{ STATIC_URL }}teleforma/images/play_168.png" width="100%" alt="{% trans 'Click here' %}" />
                 </div>
                {% endthumbnail %}
@@ -52,7 +52,7 @@
              <img src="{{ STATIC_URL }}telemeta/images/delete.png" style="vertical-align:middle" alt="" title="{% trans ' rejected' %}" />
             {% endif %}
             {% if media.item.file %}
-             <a href="{{ MEDIA_URL }}{{ media.item.file }}">
+             <a href="{{ MEDIA_URL|set_host:HOST }}{{ media.item.file }}">
               <img src="{{ STATIC_URL }}teleforma/images/download_media.png" style="vertical-align:middle" alt="" title="{% trans "Download" %}" />
              </a>
             {% endif %}