From: Guillaume Pellerin Date: Tue, 19 Nov 2013 14:50:44 +0000 (+0100) Subject: pull prof list from all depts X-Git-Tag: 1.3-TC~10 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=cf773140e06df787b859833bf735526dfa235f42;p=teleforma.git pull prof list from all depts --- 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):