]> git.parisson.com Git - teleforma.git/commitdiff
fix mp3 check and transcode AFTER fixing webm
authoryomguy <yomguy@parisson.com>
Wed, 23 Jan 2013 10:21:00 +0000 (11:21 +0100)
committeryomguy <yomguy@parisson.com>
Wed, 23 Jan 2013 10:21:00 +0000 (11:21 +0100)
teleforma/context_processors.py
tools/trans/fix_chk_media.py

index 20c2a62817388dfc62fd52ba52b4d20a3e85a7a1..c1475798eacdde24fc72d4be9125120c53fbacd6 100644 (file)
 # -*- 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']
-
-def get_ip_address(ifname):
-    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
-    ip = socket.inet_ntoa(fcntl.ioctl(
-            s.fileno(),
-            0x8915,  # SIOCGIFADDR
-            struct.pack('256s', ifname[:15])
-            )[20:24])
-    return ip
-
-def get_local_host():
-    ip = ''
-    for interface in interfaces:
-        try:
-            ip = get_ip_address(interface)
-            if ip:
-                local_ip = ip
-                break
-        except:
-            local_ip = '127.0.0.1'
-    return local_ip
-
-
-def get_http_host(request):
-    host = request.META['REMOTE_ADDR']
-    if ':' in host:
-        host = host.split(':')[0]
-    return host
-
-
-def host(request):
-    request_host = get_http_host(request)
-    local_host = get_local_host()
+# Copyright (c) 2012 Parisson SARL
+
+# This software is a computer program whose purpose is to backup, analyse,
+# transcode and stream any audio content with its metadata over a web frontend.
+
+# This software is governed by the CeCILL  license under French law and
+# abiding by the rules of distribution of free software.  You can  use,
+# modify and/ or redistribute the software under the terms of the CeCILL
+# license as circulated by CEA, CNRS and INRIA at the following URL
+# "http://www.cecill.info".
+
+# As a counterpart to the access to the source code and  rights to copy,
+# modify and redistribute granted by the license, users are provided only
+# with a limited warranty  and the software's author,  the holder of the
+# economic rights,  and the successive licensors  have only  limited
+# liability.
+
+# In this respect, the user's attention is drawn to the risks associated
+# with loading,  using,  modifying and/or developing or reproducing the
+# software by the user in light of its specific status of free software,
+# that may mean  that it is complicated to manipulate,  and  that  also
+# therefore means  that it is reserved for developers  and  experienced
+# professionals having in-depth computer knowledge. Users are therefore
+# encouraged to load and test the software's suitability as regards their
+# requirements in conditions enabling the security of their systems and/or
+# data to be ensured and,  more generally, to use and operate it in the
+# same conditions as regards security.
+
+# The fact that you are presently reading this means that you have had
+# knowledge of the CeCILL license and that you accept its terms.
+#
+# Authors: Guillaume Pellerin <yomguy@parisson.com>
+
+
+from teleforma.views.core import *
+
+
+def seminar_progress(user, seminar):    
+    """return the user progress of a seminar in percent
+    """
+
+    progress = 0
+    total = 0
+    
+    objects = [seminar.docs_1, seminar.docs_2, seminar.medias, seminar.docs_correct]
+    for obj in objects:
+        for item in obj.all():
+            total += item.weight
+            if user in item.readers.all():
+                progress += item.weight
+    
+    questions = Question.objects.filter(seminar=seminar, status=3)
+    for question in questions:
+        total += question.weight
+        answer = Answer.objects.filter(question=question, status=3, user=user)
+        if answer:
+            progress += question.weight
+
+    if total != 0:
+        return int(progress*100/total)
+    else:
+        return 0
+
+def seminar_validated(user, seminar):
+    validated = []
+    questions = seminar.question.filter(status=3)
+    if questions:
+        for question in questions:
+            answers = Answer.objects.filter(question=question, user=user, validated=True)
+            if answers:
+                validated.append(True)
+            else:
+                validated.append(False)
+        return not False in validated
+    return False
+
+def all_seminars(request, progress_order=False, date_order=False):
+    seminars = []
+
+    if isinstance(request, User):
+        user = request
+    else:
+        user = request.user
     
-    if request_host.split('.')[0] == local_host.split('.')[0] or \
-                                request_host == '127.0.0.1' or request_host == 'localhost':
-        # LAN access
-        ip = local_host
+    if not user.is_authenticated():
+        return {}
+
+    professor = user.professor.all()
+    auditor = user.auditor.all()
+
+    if professor:
+        seminars = []
+        professor = user.professor.get()
+        courses = professor.courses.all()
+        
+        for course in courses:
+            for seminar in course.seminar.all():
+                seminars.append(seminar)
+
+    elif auditor and not (user.is_staff or user.is_superuser):
+        auditor = user.auditor.get()
+        seminars = auditor.seminars.all()
+
+    elif user.is_staff or user.is_superuser:
+        seminars = Seminar.objects.all()
     else:
-        ip = settings.ROUTER_IP
+        seminars = {}
+
+    if seminars and progress_order == True:
+        s_list = [{'seminar': seminar, 'progress': seminar_progress(user, seminar)} for seminar in seminars]
+        seminars = sorted(s_list, key=lambda k: k['progress'], reverse=False)
+        seminars = [s['seminar'] for s in seminars]
+
+    if seminars and date_order == True:
+        s_list = []
+        for seminar in seminars:
+            revisions = SeminarRevision.objects.filter(user=user, seminar=seminar)
+            if revisions:
+                s_list.append({'seminar': seminar, 'date': revisions[0].date})
+            else:
+                s_list.append({'seminar': seminar, 'date': datetime.datetime.min})
+        seminars = sorted(s_list, key=lambda k: k['date'], reverse=True)
+        seminars = [s['seminar'] for s in seminars]
+
+    return {'all_seminars': seminars}
+
 
-    return {'HOST': ip }
+def total_progress(request):
+    """return the user progress of all seminars in percent"""
+
+    user = request.user
+    progress = 0
+
+    if not user.is_authenticated():
+        return {'total_progress': 0}
+
+    auditor = user.auditor.all()
+    professor = user.professor.all()
+
+    if auditor and not (user.is_staff or user.is_superuser):
+        seminars = auditor[0].seminars.all()        
+    elif user.is_superuser or user.is_staff:
+        seminars = Seminar.objects.all()
+    elif professor:
+        seminars = all_seminars(request)['all_seminars']
+    else:
+        seminars = None
+
+    for seminar in seminars:
+        progress += seminar_progress(user, seminar)
+
+    if seminars:
+        return {'total_progress': int(progress/len(seminars))}
+    else:
+        return {'total_progress': 0}
index 03a772ae790a69d76fd34cf5e95714c253d40772..9f78f69653ee6dbc1e0cadee069bd9a47bc50993 100644 (file)
@@ -15,44 +15,37 @@ class FixCheckMedia(object):
     def process(self):
         for root, dirs, files in os.walk(self.dir):
             for filename in files:
-                path = root + os.sep + filename
+                source = root + os.sep + filename
                 name = os.path.splitext(filename)[0]
                 ext = os.path.splitext(filename)[1][1:]
                 dir_files = os.listdir(root)
 
-                fixed_log = 'webm.fixed'
-                tofix_log = 'webm.tofix'
-
-                if ext == 'webm' and not fixed_log in dir_files:
-                    print path
-                    if os.path.getsize(path):
-                        self.fix_webm(path)
-                        os.system('touch ' + root + os.sep + fixed_log)
-                        #pass
-
-                if ext == 'webm' and tofix_log in dir_files and not fixed_log in dir_files:
-                    print path
-                    if os.path.getsize(path):
-                        self.fix_webm(path)
-                        os.system('touch ' + root + os.sep + fixed_log)
-                        os.system('rm ' + root + os.sep + tofix_log)
-                        #pass
-
-                fixed_log = 'mp3.fixed'
-                tofix_log = 'mp3.tofix'
-
-                if ext == 'mp3' and tofix_log in dir_files and not fixed_log in dir_files:
-                    print path
-                    for file in dir_files:
-                        source_ext = os.path.splitext(file)[1][1:]
-                        if source_ext == 'webm':
-                            source = root + os.sep + file
-                            if os.path.getsize(source):
+                webm_fixed_log = 'webm.fixed'
+                webm_tofix_log = 'webm.tofix'
+                mp3_fixed_log = 'mp3.fixed'
+                mp3_tofix_log = 'mp3.tofix'
+
+                if ext == 'webm' and os.path.getsize(source) and not webm_fixed_log in dir_files:
+                    print source    
+                    self.fix_webm(source)
+                    log = root + os.sep + webm_fixed_log
+                    os.system('touch ' + log)
+                    log = root + os.sep + webm_tofix_log
+                    if os.path.exists(log):
+                        os.system('rm ' + log)    
+            
+                    if mp3_tofix_log in dir_files and not mp3_fixed_log in dir_files:
+                        for file in dir_files:
+                            dest_ext = os.path.splitext(file)[1][1:]
+                            if dest_ext == 'mp3':
+                                dest = root + os.sep + file
                                 self.fix_mp3(source, path)
-                                os.system('touch ' + root + os.sep + fixed_log)
-                                os.system('rm ' + root + os.sep + tofix_log)
-                            break
-                            #pass
+                                log = root + os.sep + mp3_fixed_log
+                                os.system('touch ' + log)
+                                log = root + os.sep + mp3_tofix_log
+                                if os.path.exists(log):
+                                    os.system('rm ' + log)
+                                break
 
 
     def hard_fix_webm(self, path):