From 4e7ac0474b0e4f3524a48b4d22a41b397cbfbb25 Mon Sep 17 00:00:00 2001 From: Burhan Nasir Date: Fri, 12 Mar 2021 10:07:10 +0500 Subject: [PATCH] Link Instructors with multiple courses (#14) --- course_discovery/apps/course_metadata/data_loaders/api.py | 8 +++++--- .../apps/course_metadata/data_loaders/tests/test_api.py | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/course_discovery/apps/course_metadata/data_loaders/api.py b/course_discovery/apps/course_metadata/data_loaders/api.py index f336d63afb..991ade9763 100644 --- a/course_discovery/apps/course_metadata/data_loaders/api.py +++ b/course_discovery/apps/course_metadata/data_loaders/api.py @@ -19,8 +19,8 @@ from course_discovery.apps.course_metadata.data_loaders import AbstractDataLoader from course_discovery.apps.course_metadata.data_loaders.course_type import calculate_course_type from course_discovery.apps.course_metadata.models import ( - Course, CourseEntitlement, CourseRun, CourseRunType, CourseType, Organization, Program, ProgramType, Seat, SeatType, - Subject, Video, Person, PersonSocialNetwork + Course, CourseEntitlement, CourseRun, CourseRunType, CourseType, Organization, Person, PersonSocialNetwork, Program, + ProgramType, Seat, SeatType, Subject, Video ) from course_discovery.apps.course_metadata.utils import push_to_ecommerce_for_course_run, subtract_deadline_delta @@ -973,7 +973,6 @@ def _add_course_instructors(self, course_instructors, course_run): url=instructor_social['url'], ) - course_run.staff.add(instructor) else: for key, value in course_instructor.items(): setattr(instructor, key, value) @@ -986,6 +985,9 @@ def _add_course_instructors(self, course_instructors, course_run): PersonSocialNetwork.objects.bulk_update(socials, ['url']) + if not course_run.staff.filter(uuid=instructor.uuid).exists(): + course_run.staff.add(instructor) + def _process_response(self, response): """ Process the response from the WordPress. diff --git a/course_discovery/apps/course_metadata/data_loaders/tests/test_api.py b/course_discovery/apps/course_metadata/data_loaders/tests/test_api.py index 1be630b43f..51d068d6d4 100644 --- a/course_discovery/apps/course_metadata/data_loaders/tests/test_api.py +++ b/course_discovery/apps/course_metadata/data_loaders/tests/test_api.py @@ -22,7 +22,8 @@ from course_discovery.apps.course_metadata.data_loaders.tests import JPEG, JSON, mock_data from course_discovery.apps.course_metadata.data_loaders.tests.mixins import DataLoaderTestMixin from course_discovery.apps.course_metadata.models import ( - Course, CourseEntitlement, CourseRun, CourseRunType, CourseType, Organization, Person, Program, ProgramType, Seat, SeatType + Course, CourseEntitlement, CourseRun, CourseRunType, CourseType, Organization, Person, Program, ProgramType, Seat, + SeatType ) from course_discovery.apps.course_metadata.tests.factories import ( CourseEntitlementFactory, CourseFactory, CourseRunFactory, OrganizationFactory, SeatFactory, SeatTypeFactory