|
| 1 | +""" |
| 2 | +Utility methods for ol-openedx-course-propagator plugin |
| 3 | +""" |
| 4 | +from xmodule.modulestore.django import modulestore |
| 5 | +from xmodule.modulestore.django import SignalHandler |
| 6 | +from xmodule.modulestore import ModuleStoreEnum |
| 7 | +from opaque_keys.edx.locator import CourseLocator |
| 8 | +from xmodule.modulestore.django import SignalHandler |
| 9 | + |
| 10 | +from ol_openedx_course_propagator.models import CourseSyncMasterOrg, CourseSyncMapping |
| 11 | +from ol_openedx_course_propagator.tasks import async_course_propagator |
| 12 | + |
| 13 | +log = logging.getLogger(__name__) |
| 14 | + |
| 15 | + |
| 16 | +@receiver(SignalHandler.course_published) |
| 17 | +def listen_for_course_publish( |
| 18 | + sender, # noqa: ARG001 |
| 19 | + course_key, |
| 20 | + **kwargs, # noqa: ARG001 |
| 21 | +): |
| 22 | + """ |
| 23 | + Copy course content from source course to destination course. |
| 24 | + """ |
| 25 | + if CourseSyncMasterOrg.objects.filter(organization=course_key.org).exists(): |
| 26 | + # Get the source and destination course IDs |
| 27 | + course_sync_mapping = CourseSyncMapping.objects.filter( |
| 28 | + source_course=course_key |
| 29 | + ).first() |
| 30 | + if course_sync_mapping: |
| 31 | + source_course = str(course_sync_mapping.source_course) |
| 32 | + user_id = 2 |
| 33 | + for target_course_key in course_sync_mapping.target_courses.split(","): |
| 34 | + # Call the async task to copy the course content |
| 35 | + async_course_propagator.delay(user_id, source_course, target_course) |
| 36 | + else: |
| 37 | + log.warning( |
| 38 | + "No mapping found for course %s. Skipping copy.", course_key.id |
| 39 | + ) |
| 40 | + return |
| 41 | + |
0 commit comments