From cf773140e06df787b859833bf735526dfa235f42 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Tue, 19 Nov 2013 15:50:44 +0100 Subject: [PATCH] pull prof list from all depts --- teleforma/views/core.py | 42 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/teleforma/views/core.py b/teleforma/views/core.py index 5bff31a1..ba69bd46 100644 --- a/teleforma/views/core.py +++ b/teleforma/views/core.py @@ -657,28 +657,26 @@ class ProfessorListView(View): 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() + from teleforma.models import Organization, Department + departments = Department.objects.all() + for department in departments: + url = 'http://' + department.domain + '/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() class HelpView(TemplateView): -- 2.39.5