Skip to content

Commit 7c34b0e

Browse files
committed
refactoring
1 parent 4c6784c commit 7c34b0e

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

src/ol_openedx_course_sync/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
ol-openedx-course-sync plugin
33
"""
44

5-
__version__ = 0.1
65
default_app_config = "ol_openedx_course_sync.apps.OLOpenEdxCourseSyncConfig"

src/ol_openedx_course_sync/admin.py

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class CourseSyncParentOrgAdmin(admin.ModelAdmin):
1212

1313
class CourseSyncMapAdmin(admin.ModelAdmin):
1414
list_display = ("source_course", "target_courses")
15+
search_fields = ("source_course", "target_courses")
1516

1617

1718
admin.site.register(CourseSyncParentOrg, CourseSyncParentOrgAdmin)
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""
2+
Constants for ol-openedx-course-sync plugin
3+
"""
4+
COURSE_RERUN_STATE_SUCCEEDED = "succeeded"

src/ol_openedx_course_sync/signals.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
from common.djangoapps.course_action_state.models import CourseRerunState
88
from django.db.models.signals import post_save
99
from django.dispatch import receiver
10+
from xmodule.modulestore.django import SignalHandler
11+
1012
from ol_openedx_course_sync.models import CourseSyncMap, CourseSyncParentOrg
1113
from ol_openedx_course_sync.tasks import async_course_sync
12-
from xmodule.modulestore.django import SignalHandler
14+
from ol_openedx_course_sync.constants import COURSE_RERUN_STATE_SUCCEEDED
1315

1416
log = logging.getLogger(__name__)
1517

@@ -32,23 +34,23 @@ def listen_for_course_publish(
3234
return
3335

3436
source_course = str(course_sync_map.source_course)
35-
user_id = 2
37+
user_id = None
3638
for target_course_key in course_sync_map.target_courses.split(","):
3739
log.info(
3840
"Initializing async course content sync from %s to %s",
3941
source_course,
4042
target_course_key,
4143
)
4244
# Call the async task to copy the course content
43-
async_course_sync.delay(user_id, source_course, target_course_key)
45+
async_course_sync(user_id, source_course, target_course_key)
4446

4547

4648
@receiver(post_save, sender=CourseRerunState)
4749
def listen_for_course_rerun_state_post_save(sender, instance, **kwargs): # noqa: ARG001
4850
"""
4951
Listen for `CourseRerunState` post_save and update target courses in `CourseSyncMap`
5052
"""
51-
if instance.state != "succeeded":
53+
if instance.state != COURSE_RERUN_STATE_SUCCEEDED:
5254
return
5355

5456
if not CourseSyncParentOrg.objects.filter(

src/ol_openedx_course_sync/tasks.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,31 @@
99
from xmodule.modulestore import ModuleStoreEnum
1010
from xmodule.modulestore.django import SignalHandler
1111

12-
LOGGER = get_task_logger(__name__)
12+
logger = get_task_logger(__name__)
1313

1414

15-
@shared_task
15+
# @shared_task
1616
def async_course_sync(user_id, source_course_id, dest_course_id):
1717
"""
1818
Sync course content from source course to destination course.
1919
"""
20+
logger.debug(
21+
"Starting async course sync from %s to %s", source_course_id, dest_course_id
22+
)
2023
source_course_key = CourseLocator.from_string(source_course_id)
2124
dest_course_key = CourseLocator.from_string(dest_course_id)
2225

26+
logger.debug(
27+
"Copying draft course content from %s to %s", source_course_key, dest_course_key
28+
)
2329
# Copy draft branch content
2430
copy_course_content(
2531
user_id, source_course_key, dest_course_key, ModuleStoreEnum.BranchName.draft
2632
)
33+
34+
logger.debug(
35+
"Copying published course content from %s to %s", source_course_key, dest_course_key
36+
)
2737
# copy published branch content
2838
copy_course_content(
2939
user_id,
@@ -34,3 +44,6 @@ def async_course_sync(user_id, source_course_id, dest_course_id):
3444

3545
# trigger course publish signal to trigger outline and relevant updates
3646
SignalHandler.course_published.send(sender=None, course_key=dest_course_key)
47+
logger.debug(
48+
"Finished async course sync from %s to %s", source_course_key, dest_course_key
49+
)

0 commit comments

Comments
 (0)