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)
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)