]> git.parisson.com Git - teleforma.git/commitdiff
re-add host context processor
authoryomguy <yomguy@parisson.com>
Wed, 30 Jan 2013 12:03:22 +0000 (13:03 +0100)
committeryomguy <yomguy@parisson.com>
Wed, 30 Jan 2013 12:03:22 +0000 (13:03 +0100)
teleforma/context_processors.py
teleforma/views/core.py

index c1475798eacdde24fc72d4be9125120c53fbacd6..c71332d9a24f9f0226c427920813c3069c997bce 100644 (file)
 
 from teleforma.views.core import *
 
+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()
+    
+    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
+    else:
+        ip = settings.ROUTER_IP
+
+    return {'HOST': ip }
+
 
 def seminar_progress(user, seminar):    
     """return the user progress of a seminar in percent
@@ -154,3 +204,5 @@ def total_progress(request):
         return {'total_progress': int(progress/len(seminars))}
     else:
         return {'total_progress': 0}
+
+        
index eb47e34c5536ddfba8b55cd05e06e6fad6ced8d6..873cad03d86937c5f976a083d004a78aa3342c5a 100644 (file)
@@ -155,9 +155,9 @@ def get_periods(user):
         periods = Period.objects.all()
 
     if settings.TELEFORMA_E_LEARNING_TYPE == 'CRFPA':
-        student = user.crfpa_student.all()
+        student = user.student.all()
         if student:
-            student = user.crfpa_student.get()
+            student = user.student.get()
             periods = student.period.all() 
 
     elif settings.TELEFORMA_E_LEARNING_TYPE == 'AE':