Skip to content

Commit

Permalink
refactor: fix import issues
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Jan 17, 2025
1 parent 77f0d0a commit 60a596f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
23 changes: 14 additions & 9 deletions openedx/core/djangoapps/content/course_overviews/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from django.dispatch import Signal
from django.dispatch.dispatcher import receiver

from openedx.core.djangoapps.content_libraries.tasks import update_course_name_in_upstream_links
from openedx.core.djangoapps.signals.signals import COURSE_CERT_DATE_CHANGE
from xmodule.data import CertificatesDisplayBehaviors
from xmodule.modulestore.django import SignalHandler
Expand All @@ -27,6 +26,8 @@
IMPORT_COURSE_DETAILS = Signal()
# providing_args=["courserun_key"]
DELETE_COURSE_DETAILS = Signal()
# providing_args=["courserun_key", "old_name", "new_name"]
COURSE_NAME_CHANGED = Signal()


@receiver(SignalHandler.course_published)
Expand Down Expand Up @@ -222,12 +223,16 @@ def _send_course_cert_date_change_signal():

def _check_for_display_name_change(previous_course_overview, updated_course_overview):
"""
Checks for change in display name of course and triggers task to update course name in upstream->downstream entity
links table.
Checks for change in display name of course and sends COURSE_NAME_CHANGED signal.
"""
if previous_course_overview.display_name_with_default == updated_course_overview.display_name_with_default:
return
update_course_name_in_upstream_links.delay(
str(previous_course_overview.id),
updated_course_overview.display_name_with_default
)
if previous_course_overview.display_name_with_default != updated_course_overview.display_name_with_default:
COURSE_NAME_CHANGED.send(
sender=None,
courserun_key=str(previous_course_overview.id),
old_name=previous_course_overview.display_name_with_default,
new_name=updated_course_overview.display_name_with_default,
)
# update_course_name_in_upstream_links.delay(
# str(previous_course_overview.id),
# updated_course_overview.display_name_with_default
# )
15 changes: 14 additions & 1 deletion openedx/core/djangoapps/content_libraries/signal_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
from openedx_learning.api.authoring_models import Collection, CollectionPublishableEntity, Component, PublishableEntity

from lms.djangoapps.grades.api import signals as grades_signals
from openedx.core.djangoapps.content.course_overviews.signals import COURSE_NAME_CHANGED

from .api import library_component_usage_key
from .models import ContentLibrary, LtiGradedResource
from .tasks import create_or_update_xblock_upstream_link
from .tasks import create_or_update_xblock_upstream_link, update_course_name_in_upstream_links

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -234,3 +235,15 @@ def delete_upstream_downstream_link_handler(**kwargs):
return

delete_entity_link(str(xblock_info.usage_key))


@receiver(COURSE_NAME_CHANGED, dispatch_uid="update_course_name_in_upstream_links_handler")
def update_course_name_in_upstream_links_handler(courserun_key, old_name, new_name, **kwargs):
"""
Handler to update course names in upstream->downstream links on change.
"""
log.info(f"Updating course name in upstream->downstream links from '{old_name}' to '{new_name}'")
update_course_name_in_upstream_links.delay(
courserun_key,
new_name,
)

0 comments on commit 60a596f

Please sign in to comment.