]> git.parisson.com Git - teleforma.git/commitdiff
add professor list view
authorGuillaume Pellerin <yomguy@parisson.com>
Wed, 4 Jun 2014 20:10:10 +0000 (22:10 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Wed, 4 Jun 2014 20:10:10 +0000 (22:10 +0200)
teleforma/views/core.py

index ebfbbc0429562cc78c2a4b0d067d70d77e8e7c18..16f1bf75940132cc1330eafddc3e2df8c17a39a2 100644 (file)
@@ -241,7 +241,7 @@ class CourseListView(ListView):
             else:
                 course = course[0]
             course.from_dict(course_dict)
-            
+
     @jsonrpc_method('teleforma.get_dep_courses')
     def get_dep_courses(request, id):
         department = Department.objects.get(id=id)
@@ -496,7 +496,7 @@ class ConferenceRecordView(FormView):
         context['mime_type'] = 'video/webm'
         status = Status()
         status.update()
-        
+
         request_host = get_host(self.request)
         local_host = status.ip
         if request_host.split('.')[0] == local_host.split('.')[0]:
@@ -632,3 +632,36 @@ class HelpView(TemplateView):
         return super(HelpView, self).dispatch(*args, **kwargs)
 
 
+
+class ProfessorListView(View):
+
+    @jsonrpc_method('teleforma.get_professor_list')
+    def get_professor_list(request):
+        professors = Professor.objects.all()
+        return [p.to_json_dict() for p in professors]
+
+    def pull(request, host=None):
+
+        if host:
+            url = 'http://' + host + '/json/'
+        else:
+            url = 'http://' + settings.TELECASTER_MASTER_SERVER + '/json/'
+        s = ServiceProxy(url)
+
+        remote_list = s.teleforma.get_professor_list()
+        for professor_dict in remote_list['result']:
+            user, c = User.objects.get_or_create(username=professor_dict['username'])
+            user.first_name = professor_dict['first_name']
+            user.last_name = professor_dict['last_name']
+            user.email = professor_dict['email']
+            user.save()
+
+            professor, c = Professor.objects.get_or_create(user=user)
+            for course_code in professor_dict['courses']:
+                course = Course.objects.filter(code=course_code)
+                if course:
+                    if not course[0] in professor.courses.all():
+                        professor.courses.add(course[0])
+            professor.save()
+
+