Open edX Events =============== How to use ---------- Using openedx-events in your code is very straight forward. We can consider the two possible cases, sending or receiving an event. Receiving events ^^^^^^^^^^^^^^^^ This is one of the most common use cases for plugins. The edx-platform will send an event and you want to react to it in your plugin. For this you need to: 1. Include openedx-events in your dependencies. 2. Connect your receiver functions to the signals being sent. Connecting signals can be done using regular django syntax: .. code-block:: python from openedx_events.learning.signals import SESSION_LOGIN_COMPLETED @receiver(SESSION_LOGIN_COMPLETED) # your receiver function here Or at the apps.py .. code-block:: python "signals_config": { "lms.djangoapp": { "relative_path": "your_module_name", "receivers": [ { "receiver_func_name": "your_receiver_function", "signal_path": "openedx_events.learning.signals.SESSION_LOGIN_COMPLETED", }, ], } }, In case you are listening to an event in the edx-platform repo, you can directly use the django syntax since the apps.py method will not be available without the plugin. Sending events ^^^^^^^^^^^^^^ Sending events requires you to import both the event definition as well as the attr data classes that encapsulate the event data. .. code-block:: python from openedx_events.learning.data import UserData, UserPersonalData from openedx_events.learning.signals import STUDENT_REGISTRATION_COMPLETED STUDENT_REGISTRATION_COMPLETED.send_event( user=UserData( pii=UserPersonalData( username=user.username, email=user.email, name=user.profile.name, ), id=user.id, is_active=user.is_active, ), ) You can do this both from the edx-platform code as well as from an openedx plugin. Testing events ^^^^^^^^^^^^^^ Testing your code in CI, specially for plugins is now possible without having to import the complete edx-platform as a dependency. To test your functions you need to include the openedx-events library in your testing dependencies and make the signal connection in your test case. .. code-block:: python from openedx_events.learning.signals import STUDENT_REGISTRATION_COMPLETED def test_your_receiver(self): STUDENT_REGISTRATION_COMPLETED.connect(your_function) STUDENT_REGISTRATION_COMPLETED.send_event( user=UserData( pii=UserPersonalData( username='test_username', email='test_email@example.com', name='test_name', ), id=1, is_active=True, ), ) # run your assertions Changes in the openedx-events library that are not compatible with your code should break this kind of test in CI and let you know you need to upgrade your code. Live example ^^^^^^^^^^^^ For a complete and detailed example you can see the `openedx-events-2-zapier`_ plugin. This is a fully functional plugin that connects to ``STUDENT_REGISTRATION_COMPLETED`` and ``COURSE_ENROLLMENT_CREATED`` and sends the relevant information to zapier.com using a webhook. .. _openedx-events-2-zapier: https://github.com/eduNEXT/openedx-events-2-zapier Index of Events ----------------- This list contains the events currently being sent by edx-platform. The provided links target both the definition of the event in the openedx-events library as well as the trigger location in this same repository. Learning Events ^^^^^^^^^^^^^^^ .. list-table:: :widths: 35 50 20 * - *Name* - *Type* - *Date added* * - `STUDENT_REGISTRATION_COMPLETED `_ - org.openedx.learning.student.registration.completed.v1 - `2022-06-14 `_ * - `SESSION_LOGIN_COMPLETED `_ - org.openedx.learning.auth.session.login.completed.v1 - `2022-06-14 `_ * - `COURSE_ENROLLMENT_CREATED `_ - org.openedx.learning.course.enrollment.created.v1 - `2022-06-14 `_ * - `COURSE_ENROLLMENT_CHANGED `_ - org.openedx.learning.course.enrollment.changed.v1 - `2022-06-14 `_ * - `COURSE_UNENROLLMENT_COMPLETED `_ - org.openedx.learning.course.unenrollment.completed.v1 - `2022-06-14 `_ * - `CERTIFICATE_CREATED `_ - org.openedx.learning.certificate.created.v1 - `2022-06-14 `_ * - `CERTIFICATE_CHANGED `_ - org.openedx.learning.certificate.changed.v1 - `2022-06-14 `_ * - `CERTIFICATE_REVOKED `_ - org.openedx.learning.certificate.revoked.v1 - `2022-06-14 `_ * - `COHORT_MEMBERSHIP_CHANGED `_ - org.openedx.learning.cohort_membership.changed.v1 - `2022-06-14 `_ * - `COURSE_DISCUSSIONS_CHANGED `_ - org.openedx.learning.discussions.configuration.changed.v1 - `2022-06-14 `_ Content Authoring Events ^^^^^^^^^^^^^^^^^^^^^^^^ .. list-table:: :widths: 35 50 20 * - *Name* - *Type* - *Date added* * - `COURSE_CATALOG_INFO_CHANGED `_ - org.openedx.content_authoring.course.catalog_info.changed.v1 - `2022-08-24 `_ * - `XBLOCK_PUBLISHED `_ - org.openedx.content_authoring.xblock.published.v1 - `2022-12-06 `_ * - `XBLOCK_DELETED `_ - org.openedx.content_authoring.xblock.deleted.v1 - `2022-12-06 `_ * - `XBLOCK_DUPLICATED `_ - org.openedx.content_authoring.xblock.duplicated.v1 - `2022-12-06 `_ * - `XBLOCK_CREATED `_ - org.openedx.content_authoring.xblock.created.v1 - 2023-07-20 * - `XBLOCK_UPDATED `_ - org.openedx.content_authoring.xblock.updated.v1 - 2023-07-20 * - `COURSE_CREATED `_ - org.openedx.content_authoring.course.created.v1 - 2023-07-20 * - `CONTENT_LIBRARY_CREATED `_ - org.openedx.content_authoring.content_library.created.v1 - 2023-07-20 * - `CONTENT_LIBRARY_UPDATED `_ - org.openedx.content_authoring.content_library.updated.v1 - 2023-07-20 * - `CONTENT_LIBRARY_DELETED `_ - org.openedx.content_authoring.content_library.deleted.v1 - 2023-07-20 * - `LIBRARY_BLOCK_CREATED `_ - org.openedx.content_authoring.library_block.created.v1 - 2023-07-20 * - `LIBRARY_BLOCK_UPDATED `_ - org.openedx.content_authoring.library_block.updated.v1 - 2023-07-20 * - `LIBRARY_BLOCK_DELETED `_ - org.openedx.content_authoring.library_block.deleted.v1 - 2023-07-20 * - `LIBRARY_COLLECTION_CREATED `_ - org.openedx.content_authoring.content_library.collection.created.v1 - 2024-08-23 * - `LIBRARY_COLLECTION_UPDATED `_ - org.openedx.content_authoring.content_library.collection.updated.v1 - 2024-08-23 * - `LIBRARY_COLLECTION_DELETED `_ - org.openedx.content_authoring.content_library.collection.deleted.v1 - 2024-08-23 * - `CONTENT_OBJECT_ASSOCIATIONS_CHANGED `_ - org.openedx.content_authoring.content.object.associations.changed.v1 - 2024-09-06