Skip to content

Commit cb4152c

Browse files
committed
feat: Create a signal receiver and connect it up.
Add a signal receiver to the plugin and hook it up to a valid openedx-events event.
1 parent 911a763 commit cb4152c

File tree

2 files changed

+45
-28
lines changed

2 files changed

+45
-28
lines changed

backend/sample_plugin/apps.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
"""
44

55
from django.apps import AppConfig
6-
from edx_django_utils.plugins.constants import PluginSettings, PluginSignals, PluginURLs
6+
from edx_django_utils.plugins.constants import PluginSettings, PluginURLs
77

88

99
class SamplePluginConfig(AppConfig):
1010
# pylint: disable=line-too-long
1111
"""
12-
Configuration for the sample_plugin Django application.
12+
Configuration for the sample_plugin Django application as an edx-platform plugin
1313
14-
See https://github.com/openedx/edx-django-utils/blob/master/edx_django_utils/plugins/docs/how_tos/how_to_create_a_plugin_app.rst#manual-setup
14+
See https://docs.openedx.org/projects/edx-django-utils/en/latest/plugins/how_tos/how_to_create_a_plugin_app.html#manual-setup
1515
for more details and examples.
1616
""" # noqa:
1717

@@ -54,18 +54,21 @@ class SamplePluginConfig(AppConfig):
5454
},
5555
},
5656
},
57-
PluginSignals.CONFIG: {
58-
"lms.djangoapp": {
59-
PluginURLs.RELATIVE_PATH: "signals",
60-
PluginSignals.RECEIVERS: [
61-
# Signals handlers can be registered here
62-
],
63-
},
64-
"cms.djangoapp": {
65-
PluginURLs.RELATIVE_PATH: "signals",
66-
PluginSignals.RECEIVERS: [
67-
# Signals handlers can be registered here
68-
],
69-
},
70-
},
57+
# You could also define PluginSignals.CONFIG here as a part of this block
58+
# and define all our openedx-events connections here explicitly. However,
59+
# it's much easier to just put all your signal recievers in one file and import
60+
# that file below as a par of the ready() function.
61+
#
62+
# Docs for using PluginSignals can be found here:
63+
# https://docs.openedx.org/projects/edx-django-utils/en/latest/plugins/how_tos/how_to_create_a_plugin_app.html
7164
}
65+
66+
def ready(self):
67+
"""
68+
Do any app specific loading that needs to happen.
69+
"""
70+
71+
# Import the handlers file so that our signal recievers
72+
# get registered and can run when the relevant signals get
73+
# fired.
74+
from . import signals

backend/sample_plugin/signals.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
"""
22
Signal handlers for the sample_plugin application.
3+
4+
Possible signals you can listen to from the edx-platform repo are defined in the openedx-events repo. You can listen to
5+
those signals from this file which gets read as a part of django startup due to it being imported in the ready()
6+
function in apps.py
7+
8+
Useful Links:
9+
10+
- openedx-events docs: https://docs.openedx.org/projects/openedx-events/en/latest/index.html
11+
- openedx-events list of events: https://docs.openedx.org/projects/openedx-events/en/latest/reference/events.html
12+
- how to consume events: https://docs.openedx.org/projects/openedx-events/en/latest/how-tos/consume-an-event.html
13+
14+
Note: Different signals send different params to the called function so you need to look at the `data` attribute in the
15+
signal definition to know what named params are getting sent and what the data in those objects is going to be.
316
"""
417

5-
# Signal handlers can be defined here if needed
6-
# For example:
7-
# from django.dispatch import receiver
8-
# from openedx.core.djangoapps.user_api.accounts.signals import USER_RETIRE_LMS_CRITICAL
9-
#
10-
# @receiver(USER_RETIRE_LMS_CRITICAL)
11-
# def _handle_user_retirement(sender, **kwargs):
12-
# """
13-
# Handle user retirement actions for this app.
14-
# """
15-
# pass
18+
from openedx_events.content_authoring.signals import COURSE_CATALOG_INFO_CHANGED
19+
from openedx_events.content_authoring.data import CourseCatalogData
20+
from django.dispatch import receiver
21+
import logging
22+
23+
logger = logging.getLogger(__name__)
24+
25+
@receiver(COURSE_CATALOG_INFO_CHANGED)
26+
def log_course_info_changed(signal, sender, catalog_info: CourseCatalogData, **kwargs):
27+
logging.info(f"{catalog_info.course_key} has been updated!")
28+
29+
# Then you could take some action related to your personal systems here

0 commit comments

Comments
 (0)