]> git.parisson.com Git - teleforma.git/commitdiff
pull courses from all departments
authorGuillaume Pellerin <yomguy@parisson.com>
Tue, 12 Nov 2013 15:08:00 +0000 (16:08 +0100)
committerGuillaume Pellerin <yomguy@parisson.com>
Tue, 12 Nov 2013 15:08:00 +0000 (16:08 +0100)
teleforma/management/commands/teleforma-pull-courses.py
teleforma/views/core.py

index 9835cd4bfc4c7ca4d553cad9521dc3a2153dadfd..7e4cb05e3ad4e10d7d3c848136868de8acebf8b1 100644 (file)
@@ -12,12 +12,12 @@ import codecs
 
 
 class Command(BaseCommand):
-    help = "pull teleforma courses from a remote host"
+    help = "pull teleforma courses from a remote host for an organization"
     admin_email = 'webmaster@parisson.com'
-    args = "organization_name department_name"
+    args = "organization_name"
 
     def handle(self, *args, **options):
        organization_name = args[-2]
        department_name = args[-1]
         view = CourseListView()
-        view.pull(organization_name, department_name)
+        view.pull(organization_name)
index c0d9b7559c998872cfa03b767c0b5233fee89a70..5b40ff7b676080f300c0f5b87b74aa4cf561307c 100644 (file)
@@ -240,21 +240,21 @@ class CourseListView(CourseAccessMixin, ListView):
         department = Department.objects.get(organization=organization, name=department_name)
         return [course.to_dict() for course in Course.objects.filter(department=department)]
 
-    def pull(request, organization_name, department_name):
+    def pull(request, organization_name):
         organization = Organization.objects.get(name=organization_name)
-        department = Department.objects.get(name=department_name, organization=organization)
-        url = 'http://' + department.domain + '/json/'
-        s = ServiceProxy(url)
-
-        remote_list = s.teleforma.get_course_list(organization_name, department.name)
-        for course_dict in remote_list['result']:
-            course = Course.objects.filter(code=course_dict['code'])
-            if not course:
-                course = Course()
-            else:
-                course = course[0]
-            course.from_dict(course_dict)
-            
+        departments = Department.objects.filter(organization=organization)
+        for department in departments:
+            url = 'http://' + department.domain + '/json/'
+            s = ServiceProxy(url)
+            remote_list = s.teleforma.get_course_list(organization_name, department.name)
+            for course_dict in remote_list['result']:
+                course = Course.objects.filter(code=course_dict['code'])
+                if not course:
+                    course = Course()
+                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)