From: Guillaume Pellerin Date: Thu, 20 Jul 2017 00:06:41 +0000 (+0200) Subject: Merge branch 'dev' into tc202 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=46b973f1520e0649fa9bab2d178011448ed48837;p=teleforma.git Merge branch 'dev' into tc202 --- 46b973f1520e0649fa9bab2d178011448ed48837 diff --cc teleforma/views/core.py index 28e50049,d3b634fe..8b54250d --- a/teleforma/views/core.py +++ b/teleforma/views/core.py @@@ -746,43 -747,35 +746,43 @@@ 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() + from teleforma.models import Organization, Department + departments = Department.objects.all() + professors_old = Professor.objects.all() + professors_new = [] - 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() + 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() + professors_new.append(professor) + #print professor + + for professor in professors_old: + if not professor in professors_new: + professor.delete() - class WebClassGroupView(View): + class ClassGroupView(View): - @jsonrpc_method('teleforma.get_web_class_group_list') - def get_web_class_group_list(request): - web_class_groups = WebClassGroup.objects.all() - return [w.to_json_dict() for w in web_class_groups] + @jsonrpc_method('teleforma.get_class_group_list') + def get_class_group_list(request): + class_groups = ClassGroup.objects.all() + return [w.to_json_dict() for w in class_groups] def pull(request, host=None): if host: