From 910f6e87fb01c9d590e3b1ecd4513bb2d3d1203b Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Tue, 12 Nov 2013 16:08:00 +0100 Subject: [PATCH] pull courses from all departments --- .../commands/teleforma-pull-courses.py | 6 ++-- teleforma/views/core.py | 28 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/teleforma/management/commands/teleforma-pull-courses.py b/teleforma/management/commands/teleforma-pull-courses.py index 9835cd4b..7e4cb05e 100644 --- a/teleforma/management/commands/teleforma-pull-courses.py +++ b/teleforma/management/commands/teleforma-pull-courses.py @@ -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) diff --git a/teleforma/views/core.py b/teleforma/views/core.py index c0d9b755..5b40ff7b 100644 --- a/teleforma/views/core.py +++ b/teleforma/views/core.py @@ -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) -- 2.39.5