openedx.core.djangoapps.notifications package#
Subpackages#
- openedx.core.djangoapps.notifications.config package
- openedx.core.djangoapps.notifications.email package
- Submodules
- openedx.core.djangoapps.notifications.email.events module
- openedx.core.djangoapps.notifications.email.message_type module
- openedx.core.djangoapps.notifications.email.notification_icons module
NotificationTypeIconsNotificationTypeIcons.CHECK_CIRCLE_GREENNotificationTypeIcons.HELP_OUTLINENotificationTypeIcons.NEWSPAPERNotificationTypeIcons.OPEN_RESPONSE_OUTLINENotificationTypeIcons.POST_OUTLINENotificationTypeIcons.QUESTION_ANSWER_OUTLINENotificationTypeIcons.REPORT_REDNotificationTypeIcons.VERIFIEDNotificationTypeIcons.get_icon_name_for_notification_type()NotificationTypeIcons.get_icon_url_for_notification_type()
- openedx.core.djangoapps.notifications.email.tasks module
- openedx.core.djangoapps.notifications.email.utils module
add_additional_attributes_to_notifications()add_headers_to_email_message()add_zero_margin_to_root()create_app_notifications_dict()create_datetime_string()create_email_digest_context()create_email_template_context()create_missing_account_level_preferences()decrypt_string()encrypt_string()filter_email_enabled_notifications()filter_notification_with_email_enabled_preferences()get_course_info()get_enabled_notification_types_for_cadence()get_icon_url_for_notification_type()get_language_preference_for_users()get_start_end_date()get_text_for_notification_type()get_time_ago()get_translated_app_title()get_unique_course_ids()get_unsubscribe_link()is_email_notification_flag_enabled()is_notification_type_channel_editable()update_user_preferences_from_patch()username_from_hash()
- Module contents
- openedx.core.djangoapps.notifications.management package
- Subpackages
- openedx.core.djangoapps.notifications.management.commands package
- Submodules
- openedx.core.djangoapps.notifications.management.commands.delete_expired_notifications module
- openedx.core.djangoapps.notifications.management.commands.delete_notifications module
- openedx.core.djangoapps.notifications.management.commands.fix_mixed_email_cadence module
- openedx.core.djangoapps.notifications.management.commands.send_email_digest module
- openedx.core.djangoapps.notifications.management.commands.update_notification_preferences module
- Module contents
- openedx.core.djangoapps.notifications.management.commands package
- Module contents
- Subpackages
- openedx.core.djangoapps.notifications.push package
Submodules#
openedx.core.djangoapps.notifications.apps module#
Config for notifications app
openedx.core.djangoapps.notifications.audience_filters module#
Audience based filters for notifications and Notification filters
- class openedx.core.djangoapps.notifications.audience_filters.CohortAudienceFilter(course_key)#
Bases:
NotificationAudienceFilterBaseFilter class for cohort roles
- filter(group_ids)#
Filter users based on their cohort ids
- class openedx.core.djangoapps.notifications.audience_filters.CourseRoleAudienceFilter(course_key)#
Bases:
NotificationAudienceFilterBaseFilter class for course roles
- allowed_filters = ['staff', 'instructor']#
- filter(course_roles)#
Filter users based on their course roles
- class openedx.core.djangoapps.notifications.audience_filters.EnrollmentAudienceFilter(course_key)#
Bases:
NotificationAudienceFilterBaseFilter class for enrollment modes
- allowed_filters = ['audit', 'credit', 'honor', 'no-id-professional', 'professional', 'verified', 'masters', 'executive-education', 'paid-executive-education', 'unpaid-executive-education', 'paid-bootcamp', 'unpaid-bootcamp']#
- filter(enrollment_modes)#
Filter users based on their course enrollment modes
- class openedx.core.djangoapps.notifications.audience_filters.ForumRoleAudienceFilter(course_key)#
Bases:
NotificationAudienceFilterBaseFilter class for roles
- allowed_filters = ['Administrator', 'Moderator', 'Group Moderator', 'Community TA', 'Student']#
- filter(roles)#
Filter users based on their roles
- class openedx.core.djangoapps.notifications.audience_filters.NotificationAudienceFilterBase(course_key)#
Bases:
objectBase class for notification audience filters
- allowed_filters = []#
- abstractmethod filter(values)#
- is_valid_filter(values)#
- class openedx.core.djangoapps.notifications.audience_filters.NotificationFilter#
Bases:
objectFilter notifications based on their type
- apply_filters(user_ids, course_key, notification_type) list#
Apply all the filters
- filter_audit_expired_users_with_no_role(user_ids, course) list#
Check if the user has access to the course this would be true if the user has a course role or a forum role
- static get_users_with_course_role(user_ids: List[int], course_id: str) List[int]#
Get users with a course role for the given course.
- static get_users_with_forum_roles(user_ids: List[int], course_id: str) List[int]#
Get users with forum roles for the given course.
- class openedx.core.djangoapps.notifications.audience_filters.TeamAudienceFilter(course_key)#
Bases:
NotificationAudienceFilterBaseFilter class for team roles
- filter(team_ids)#
Filter users based on team id
openedx.core.djangoapps.notifications.base_notification module#
Base setup for Notification Apps and Types.
- class openedx.core.djangoapps.notifications.base_notification.NotificationAppManager#
Bases:
objectNotification app manager
- add_core_notification_non_editable(notification_app_attrs, non_editable_channels)#
Adds non_editable for core notification.
- add_core_notification_preference(notification_app_attrs, notification_types, email_opt_out=False)#
Adds core notification preference for the given notification app.
- get_notification_app_preferences(email_opt_out=False)#
Returns notification app preferences for the given name.
- class openedx.core.djangoapps.notifications.base_notification.NotificationPreferenceSyncManager#
Bases:
objectSync Manager for Notification Preferences
- static denormalize_preferences(normalized_preferences)#
Denormalizes preference from simplified to normal structure for saving it in database
- static normalize_preferences(preferences)#
Normalizes preferences to reduce depth of structure. This simplifies matching of preferences reducing effort to get difference.
- static update_preferences(preferences, email_opt_out=False)#
Creates a new preference version from old preferences. New preference is created instead of updating old preference
- Steps to update existing user preference
Normalize existing user preference
Normalize default preferences
Iterate over all the apps in default preference, if app_name exists in existing preference, update new preference app enabled value as existing enabled value
Iterate over all preferences, if preference_name exists in existing preference, update new preference values of web, email and push as existing web, email and push respectively
Denormalize new preference
- class openedx.core.djangoapps.notifications.base_notification.NotificationTypeManager#
Bases:
objectManager for notification types
- get_core_and_non_core_notification_types(notification_app)#
Returns core notification types for the given app name.
- static get_non_core_notification_type_preferences(non_core_notification_types, email_opt_out=False)#
Returns non-core notification type preferences for the given notification types.
- static get_non_editable_notification_channels(notification_types)#
Returns non_editable notification channels for the given notification types.
- get_notification_app_preference(notification_app, email_opt_out=False)#
Returns notification app preferences for the given notification app.
- get_notification_types_by_app(notification_app)#
Returns notification types for the given notification app.
- openedx.core.djangoapps.notifications.base_notification.get_default_values_of_preference(notification_app, notification_type)#
Returns default preference for notification_type
- openedx.core.djangoapps.notifications.base_notification.get_notification_content(notification_type, context)#
Returns notification content for the given notification type with provided context.
Args: notification_type (str): The type of notification (e.g., ‘course_update’). context (dict): The context data to be used in the notification template.
Returns: str: Rendered notification content based on the template and context.
openedx.core.djangoapps.notifications.email_notifications module#
Email notifications module.
- class openedx.core.djangoapps.notifications.email_notifications.EmailCadence#
Bases:
objectEmail cadence class
- DAILY = 'Daily'#
- EMAIL_CADENCE_CHOICES = [('Daily', 'Daily'), ('Weekly', 'Weekly'), ('Immediately', 'Immediately'), ('Never', 'Never')]#
- EMAIL_CADENCE_CHOICES_DICT = {'Daily': 'Daily', 'Immediately': 'Immediately', 'Never': 'Never', 'Weekly': 'Weekly'}#
- IMMEDIATELY = 'Immediately'#
- NEVER = 'Never'#
- WEEKLY = 'Weekly'#
- classmethod get_email_cadence_choices()#
Returns email cadence choices.
- classmethod get_email_cadence_value(email_cadence)#
Returns email cadence display for the given email cadence.
openedx.core.djangoapps.notifications.events module#
Events for notification app.
- openedx.core.djangoapps.notifications.events.get_user_course_roles(user, course_id)#
Get the user’s roles in the course.
- openedx.core.djangoapps.notifications.events.get_user_forums_roles(user, course_id)#
Get the user’s roles in the course forums.
- openedx.core.djangoapps.notifications.events.notification_event_context(user, course_id, notification)#
- openedx.core.djangoapps.notifications.events.notification_generated_event(user_ids, app_name, notification_type, course_key, content_url, content, sender_id=None)#
Emit an event when a notification is generated.
- openedx.core.djangoapps.notifications.events.notification_preference_unsubscribe_event(user, is_preference_updated=False)#
Emits an event when user clicks on one-click-unsubscribe url
- openedx.core.djangoapps.notifications.events.notification_preference_update_event(user, course_id, updated_preference)#
Emit an event when a notification preference is updated.
- openedx.core.djangoapps.notifications.events.notification_read_event(user, notification, first_read=False)#
Emit an event when a notification app is marked read for a user.
- openedx.core.djangoapps.notifications.events.notification_tray_opened_event(user, unseen_notifications_count)#
Emit an event when a notification tray is opened.
- openedx.core.djangoapps.notifications.events.notifications_app_all_read_event(user, app_name)#
Emit an event when a notification is read.
openedx.core.djangoapps.notifications.exceptions module#
Notification-related exceptions.
- exception openedx.core.djangoapps.notifications.exceptions.InvalidNotificationTypeError#
Bases:
ExceptionException raised when an invalid notification type is passed.
openedx.core.djangoapps.notifications.grouping_notifications module#
Notification grouping utilities for notifications
- class openedx.core.djangoapps.notifications.grouping_notifications.BaseNotificationGrouper#
Bases:
ABCBase class for notification groupers.
- abstractmethod group(new_notification, old_notification)#
- class openedx.core.djangoapps.notifications.grouping_notifications.NewPostGrouper#
Bases:
BaseNotificationGrouperGroups new post notifications based on the author name.
- group(new_notification, old_notification)#
Groups new post notifications based on the author name.
- class openedx.core.djangoapps.notifications.grouping_notifications.NotificationRegistry#
Bases:
objectRegistry for notification groupers.
- classmethod get_grouper(notification_type: str) BaseNotificationGrouper | None#
Retrieves the appropriate notification grouper based on the given notification type.
- Parameters:
notification_type – The type of notification for which to retrieve the grouper.
- Returns:
The corresponding BaseNotificationGrouper instance or None if no grouper is found.
- classmethod register(notification_type: str)#
Registers a notification grouper for the given notification type. Args
notification_type: The type of notification for which to register the grouper.
- Returns:
A decorator that registers the grouper class for the given notification type.
- class openedx.core.djangoapps.notifications.grouping_notifications.OraStaffGrouper#
Bases:
BaseNotificationGrouperGrouper for new ora staff notifications.
- group(new_notification, old_notification)#
Groups new ora staff notifications based on the xblock ID.
- openedx.core.djangoapps.notifications.grouping_notifications.get_user_existing_notifications(user_ids, notification_type, group_by_id, course_id)#
Returns user last group able notification
- openedx.core.djangoapps.notifications.grouping_notifications.group_user_notifications(new_notification: Notification, old_notification: Notification)#
Groups user notification based on notification type and group_id
openedx.core.djangoapps.notifications.handlers module#
Handlers for notifications
- openedx.core.djangoapps.notifications.handlers.calculate_course_wide_notification_audience(course_key, audience_filters)#
Calculate the audience for a course-wide notification based on the audience filters
- openedx.core.djangoapps.notifications.handlers.create_user_account_preferences(sender, instance, created, **kwargs)#
Initialize user notification preferences when new user is created.
- openedx.core.djangoapps.notifications.handlers.generate_course_notifications(signal, sender, course_notification_data, metadata, **kwargs)#
Watches for COURSE_NOTIFICATION_REQUESTED signal and calls send_notifications task
- openedx.core.djangoapps.notifications.handlers.generate_user_notifications(signal, sender, notification_data, metadata, **kwargs)#
Watches for USER_NOTIFICATION_REQUESTED signal and calls send_web_notifications task
openedx.core.djangoapps.notifications.models module#
Models for notifications
- class openedx.core.djangoapps.notifications.models.CourseNotificationPreference(*args, **kwargs)#
Bases:
TimeStampedModelModel to store notification preferences for users
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- config_version#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- course_id#
DO NOT REUSE THIS CLASS. Provided for backwards compatibility only!
A placeholder class that provides a way to set the attribute on the model.
- created#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_app_config(app_name) Dict#
Returns the app config for the given app name.
- get_channels_for_notification_type(app_name, notification_type) list#
Returns the channels for the given app name and notification type. if notification is core then return according to core settings Sample Response: [‘web’, ‘push’]
- get_core_config(app_name) Dict#
Returns the core config for the given app name.
Sample Response: {
‘email’: True, ‘push’: True, ‘web’: True, ‘info’: ‘comment on post and response on comment’
}
- get_email_cadence_for_notification_type(app_name, notification_type) str#
Returns the email cadence for the given app name and notification type.
- get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
- get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
- get_notification_type_config(app_name, notification_type) Dict#
Returns the notification type config for the given app name and notification type.
Sample Response: {
‘email’: True, ‘push’: True, ‘web’: True, ‘info’: ‘Comment on post’
}
- get_notification_types(app_name) Dict#
Returns the notification types for the given app name.
Sample Response: {
- ‘new_comment_on_post’: {
‘email’: True, ‘push’: True, ‘web’: True, ‘info’: ‘Comment on post’
}, ‘new_response_on_comment’: {
‘email’: True, ‘push’: True, ‘web’: True, ‘info’: ‘Response on comment’
},
- get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
- get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
- static get_updated_user_course_preferences(user, course_id)#
- static get_user_course_preference(user_id, course_id)#
Returns updated courses preferences for a user
- static get_user_notification_preferences(user)#
Checks if all user preferences have updated versions and returns the user preferences. Updates any preferences that need to be updated to the latest config version.
- get_web_config(app_name, notification_type) bool#
Returns the web config for the given app name and notification type.
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- is_active#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- is_core(app_name, notification_type) bool#
Returns True if the given notification type is a core notification type.
- is_email_enabled_for_notification_type(app_name, notification_type) bool#
Returns True if the email is enabled for the given app name and notification type.
- is_enabled_for_any_channel(app_name, notification_type) bool#
Returns True if the notification type is enabled for any channel.
- modified#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- notification_preference_config#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>#
- user#
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- user_id#
- class openedx.core.djangoapps.notifications.models.Notification(*args, **kwargs)#
Bases:
TimeStampedModelModel to store notifications for users
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- app_name#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- property content#
Returns the content for the notification.
- content_context#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- content_url#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- course_id#
DO NOT REUSE THIS CLASS. Provided for backwards compatibility only!
A placeholder class that provides a way to set the attribute on the model.
- created#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- email#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
- get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
- get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
- get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
- group_by_id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- last_read#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- last_seen#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- modified#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- notification_type#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>#
- push#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- user#
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- user_id#
- web#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class openedx.core.djangoapps.notifications.models.NotificationPreference(*args, **kwargs)#
Bases:
TimeStampedModelModel to store notification preferences for users at account level
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- class EmailCadenceChoices(value)#
Bases:
TextChoices- DAILY = 'Daily'#
- IMMEDIATELY = 'Immediately'#
- WEEKLY = 'Weekly'#
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- app#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- classmethod create_default_preferences_for_user(user_id) list#
Creates all preferences for user Note: It creates preferences using bulk create, so primary key will be missing for newly created preference. Refetch if primary key is needed
- created#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- email#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- email_cadence#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_channels_for_notification_type(*args, **kwargs) list#
Returns the channels for the given app name and notification type. Sample Response: [‘web’, ‘push’]
- get_email_cadence_display(*, field=<django.db.models.fields.CharField: email_cadence>)#
- get_email_cadence_for_notification_type(*args, **kwargs) str#
Returns the email cadence for the notification type.
- get_next_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=True, **kwargs)#
- get_next_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=True, **kwargs)#
- get_previous_by_created(*, field=<model_utils.fields.AutoCreatedField: created>, is_next=False, **kwargs)#
- get_previous_by_modified(*, field=<model_utils.fields.AutoLastModifiedField: modified>, is_next=False, **kwargs)#
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- is_active#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- is_enabled_for_any_channel(*args, **kwargs) bool#
Returns True if the notification preference is enabled for any channel.
- modified#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>#
- push#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- type#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- user#
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- user_id#
- web#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- openedx.core.djangoapps.notifications.models.create_notification_preference(user_id: int, notification_type: str)#
Create a single notification preference with appropriate defaults. :param user_id: ID of the user :param notification_type: Type of notification
- Returns:
NotificationPreference instance
- openedx.core.djangoapps.notifications.models.get_additional_notification_channel_settings()#
Returns the additional notification channel settings.
- openedx.core.djangoapps.notifications.models.get_course_notification_preference_config()#
Returns the course specific notification preference config.
Sample Response: {
- ‘discussion’: {
‘enabled’: True, ‘not_editable’: {
‘new_comment_on_post’: [‘push’], ‘new_response_on_post’: [‘web’], ‘new_response_on_comment’: [‘web’, ‘push’]
}, ‘notification_types’: {
- ‘new_comment_on_post’: {
‘email’: True, ‘push’: True, ‘web’: True, ‘info’: ‘Comment on post’
}, ‘new_response_on_comment’: {
‘email’: True, ‘push’: True, ‘web’: True, ‘info’: ‘Response on comment’
}, ‘new_response_on_post’: {
‘email’: True, ‘push’: True, ‘web’: True, ‘info’: ‘New Response on Post’
}, ‘core’: {
‘email’: True, ‘push’: True, ‘web’: True, ‘info’: ‘comment on post and response on comment’
}
}, ‘core_notification_types’: []
}
}
- openedx.core.djangoapps.notifications.models.get_course_notification_preference_config_version()#
Returns the notification preference config version.
- openedx.core.djangoapps.notifications.models.get_notification_channels()#
Returns the notification channels.
openedx.core.djangoapps.notifications.notification_content module#
Helper functions for overriding notification content for given notification type.
- openedx.core.djangoapps.notifications.notification_content.get_comment_on_followed_post_notification_context(context: Dict) Dict#
Returns the context for the given notification type with the author pronoun.
- openedx.core.djangoapps.notifications.notification_content.get_new_comment_notification_context(context: Dict) Dict#
Returns the context for the given notification type with the author pronoun.
- openedx.core.djangoapps.notifications.notification_content.get_notification_context_with_author_pronoun(context: Dict) Dict#
Returns the context for the given notification type with the author pronoun.
- openedx.core.djangoapps.notifications.notification_content.get_notification_type_context_function(notification_type) callable#
- Returns:
The function that returns the context for the given notification type.
- Return type:
callable
openedx.core.djangoapps.notifications.permissions module#
Permissions for notifications
- openedx.core.djangoapps.notifications.permissions.allow_any_authenticated_user()#
Function and class decorator that abstracts the authentication and permission checks for api views. Allows both verified and non-verified users
openedx.core.djangoapps.notifications.policies module#
Policies for the notifications app.
openedx.core.djangoapps.notifications.serializers module#
Serializers for the notifications API.
- class openedx.core.djangoapps.notifications.serializers.CourseOverviewSerializer(*args, **kwargs)#
Bases:
ModelSerializerSerializer for CourseOverview model.
- class Meta#
Bases:
object- fields = ('id', 'display_name')#
- model#
alias of
CourseOverview
- class openedx.core.djangoapps.notifications.serializers.NotificationSerializer(*args, **kwargs)#
Bases:
ModelSerializerSerializer for the Notification model.
- class Meta#
Bases:
object- fields = ('id', 'app_name', 'notification_type', 'content_context', 'content', 'content_url', 'course_id', 'last_read', 'last_seen', 'created')#
- model#
alias of
Notification
- class openedx.core.djangoapps.notifications.serializers.UserNotificationPreferenceUpdateAllSerializer(*args, **kwargs)#
Bases:
SerializerSerializer for user notification preferences update with custom field validators.
- validate(attrs)#
Cross-field validation for notification preference update.
- openedx.core.djangoapps.notifications.serializers.add_info_to_notification_config(config_obj)#
Enhances the notification configuration by appending descriptive ‘info’ to each notification type.
This function supports two different structures of config_obj, depending on the source of the data: either from the account preferences API (AggregatedNotificationPreferences) or the course preferences API (UserNotificationPreferenceView).
Supported input structures:
- From account preferences API:
- {
- ‘notification_app’: {
- ‘notification_types’: {
‘core’: { … }, ‘non-core’: { … }
}
}
}
- From course preferences API:
- {
- ‘notification_preference_config’: {
- ‘notification_app’: {
- ‘notification_types’: {
‘core’: { … }, ‘non-core’: { … }
}
}
}
}
For each notification type: - If the type is ‘core’, its info is fetched from COURSE_NOTIFICATION_APPS[notification_app][‘core_info’]. - For all other types, info is fetched from COURSE_NOTIFICATION_TYPES[notification_type][‘info’].
- Parameters:
config_obj (dict) – The notification configuration object to enhance.
- Returns:
The enhanced configuration object with added ‘info’ fields.
- Return type:
dict
- openedx.core.djangoapps.notifications.serializers.add_non_editable_in_preference(preference)#
Add non_editable preferences to the preference dict
- openedx.core.djangoapps.notifications.serializers.get_non_editable_channels(app_name)#
Returns a dict of notification: [non-editable channels] for the given app name.
- openedx.core.djangoapps.notifications.serializers.validate_email_cadence(email_cadence: str) str#
Validate email cadence value.
- openedx.core.djangoapps.notifications.serializers.validate_notification_app(notification_app: str) str#
Validate notification app value.
- openedx.core.djangoapps.notifications.serializers.validate_notification_app_enabled(notification_app: str) str#
Validate notification app is enabled.
- openedx.core.djangoapps.notifications.serializers.validate_notification_channel(notification_channel: str) str#
Validate notification channel value.
- openedx.core.djangoapps.notifications.serializers.validate_notification_type(notification_type: str) str#
Validate notification type value.
openedx.core.djangoapps.notifications.tasks module#
This file contains celery tasks for notifications.
- openedx.core.djangoapps.notifications.tasks.create_account_notification_pref_if_not_exists(user_ids: List, preferences: List, notification_type: str)#
Create account level notification preference if not exist.
- openedx.core.djangoapps.notifications.tasks.create_notification_preference(user_id: int, notification_type: str) NotificationPreference#
Create a single notification preference with appropriate defaults.
- Parameters:
user_id – ID of the user
notification_type – Type of notification
- Returns:
NotificationPreference instance
- openedx.core.djangoapps.notifications.tasks.is_notification_valid(notification_type, context)#
Validates notification before creation
- openedx.core.djangoapps.notifications.tasks.update_account_user_preference(user_id: int) None#
Update account level user preferences to ensure all notification types are present.
openedx.core.djangoapps.notifications.urls module#
URLs for the notifications API.
openedx.core.djangoapps.notifications.utils module#
Utils function for notifications app
- openedx.core.djangoapps.notifications.utils.clean_arguments(kwargs)#
Returns query arguments from command line arguments
- openedx.core.djangoapps.notifications.utils.exclude_inaccessible_preferences(user_preferences: dict, user)#
Exclude notifications from user preferences that the user has no access to, based on forum and course roles.
- Parameters:
user_preferences – Dictionary of user notification preferences
user – Django User object
- Returns:
Updated user_preferences dictionary (modified in-place)
- openedx.core.djangoapps.notifications.utils.filter_out_visible_notifications(user_preferences: dict, notifications_with_visibility: Dict[str, List[str]], user_forum_roles: List[str], user_course_roles: List[str]) dict#
Filter out notifications visible to forum roles from user preferences.
- Parameters:
user_preferences – User preferences dictionary
notifications_with_visibility – List of dictionaries with notification type names and
corresponding visibility settings :param user_forum_roles: List of forum roles for the user :param user_course_roles: List of course roles for the user :return: Updated user preferences dictionary
- openedx.core.djangoapps.notifications.utils.find_app_in_normalized_apps(app_name, apps_list)#
Returns app preference based on app_name
- openedx.core.djangoapps.notifications.utils.find_pref_in_normalized_prefs(pref_name, app_name, prefs_list)#
Returns preference based on preference_name and app_name
- openedx.core.djangoapps.notifications.utils.get_list_in_batches(input_list, batch_size)#
Divides the list of objects into list of list of objects each of length batch_size.
- openedx.core.djangoapps.notifications.utils.get_notification_types_with_visibility_settings() Dict[str, List[str]]#
Get notification types with their visibility settings.
- Returns:
List of dictionaries with notification type names and corresponding visibility settings
- openedx.core.djangoapps.notifications.utils.get_show_notifications_tray(user)#
Returns show_notifications_tray as boolean for the courses in which user is enrolled
- openedx.core.djangoapps.notifications.utils.get_user_forum_access_roles(user_id: int) List[str]#
Get forum roles for the given user in all course.
- Parameters:
user_id – User ID
- Returns:
List of forum roles
- openedx.core.djangoapps.notifications.utils.get_user_forum_roles(user_id: int, course_id: str) List[str]#
Get forum roles for the given user in the specified course.
- Parameters:
user_id – User ID
course_id – Course ID
- Returns:
List of forum roles
- openedx.core.djangoapps.notifications.utils.process_app_config(app_config: Dict, user_config: Dict, app: str, default_config: Dict) None#
Process a single category configuration against another config.
- openedx.core.djangoapps.notifications.utils.remove_preferences_with_no_access(preferences: dict, user) dict#
Filter out notifications visible to forum roles from user preferences.
- Parameters:
preferences – User preferences dictionary
user – User object
- Returns:
Updated user preferences dictionary
- openedx.core.djangoapps.notifications.utils.update_core_notification_types(app_config: Dict, user_config: Dict) None#
Update core notification types by merging existing and new types.
- openedx.core.djangoapps.notifications.utils.update_notification_fields(target_config: Dict, source_config: Dict) None#
Update individual notification fields (web, push, email) and email_cadence.
- openedx.core.djangoapps.notifications.utils.update_notification_types(app_config: Dict, user_app_config: Dict) None#
Update notification types for a specific category configuration.
openedx.core.djangoapps.notifications.views module#
Views for the notifications API.
- class openedx.core.djangoapps.notifications.views.MarkNotificationsSeenAPIView(**kwargs)#
Bases:
UpdateAPIViewAPI view for marking user’s all notifications seen for a provided app_name.
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
- update(request, *args, **kwargs)#
Marks all notifications for the given app name seen for the authenticated user.
- Args:
app_name: The name of the app to mark notifications seen for.
- Response Format:
A Response object with a 200 OK status code if the notifications were successfully marked seen.
Response Error Codes: - 400: Bad Request status code if the app name is invalid.
- class openedx.core.djangoapps.notifications.views.NotificationCountView(**kwargs)#
Bases:
APIViewAPI view for getting the unseen notifications count and show_notification_tray flag for a user.
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- get(request)#
Get the unseen notifications count and show_notification_tray flag for a user.
Permissions: User must be authenticated. Response Format: ```json {
“show_notifications_tray”: (bool) show_notifications_tray, “count”: (int) total_number_of_unseen_notifications, “count_by_app_name”: {
(str) app_name: (int) number_of_unseen_notifications, …
}, “notification_expiry_days”: 60
}#
Response Error Codes: - 403: The requester cannot access resource.
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
- class openedx.core.djangoapps.notifications.views.NotificationListAPIView(**kwargs)#
Bases:
ListAPIViewAPI view for listing notifications for a user.
Permissions: User must be authenticated. Response Format (paginated):
- {
- “results”[
- {
“id”: (int) notification_id, “app_name”: (str) app_name, “notification_type”: (str) notification_type, “content”: (str) content, “content_context”: (dict) content_context, “content_url”: (str) content_url, “last_read”: (datetime) last_read, “last_seen”: (datetime) last_seen
], “count”: (int) total_number_of_notifications, “next”: (str) url_to_next_page_of_notifications, “previous”: (str) url_to_previous_page_of_notifications, “page_size”: (int) number_of_notifications_per_page,
}
Response Error Codes: - 403: The requester cannot access resource.
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- get_queryset()#
Override the get_queryset method to filter the queryset by app name, request.user and created
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
- serializer_class#
alias of
NotificationSerializer
- class openedx.core.djangoapps.notifications.views.NotificationPreferencesView(**kwargs)#
Bases:
APIViewAPI view to retrieve and structure the notification preferences for the authenticated user.
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- get(request)#
Handles GET requests to retrieve notification preferences.
This method fetches the user’s active notification preferences and merges them with a default structure provided by NotificationAppManager. This provides a complete view of all possible notifications and the user’s current settings for them.
- Returns:
- A DRF Response object containing the structured
notification preferences or an error message.
- Return type:
Response
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
- put(request)#
Handles PUT requests to update notification preferences.
This method updates the user’s notification preferences based on the provided data in the request body. It expects a dictionary with notification types and their settings.
- Returns:
A DRF Response object indicating success or failure.
- Return type:
Response
- class openedx.core.djangoapps.notifications.views.NotificationReadAPIView(**kwargs)#
Bases:
APIViewAPI view for marking user notifications as read, either all notifications or a single notification
- authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
- patch(request, *args, **kwargs)#
Marks all notifications or single notification read for the given app name or notification id for the authenticated user.
Requests: PATCH /api/notifications/read/
- Parameters:
request (Request) –
The request object containing the app name or notification id. {
”app_name”: (str) app_name, “notification_id”: (int) notification_id
}
Returns: - 200: OK status code if the notification or notifications were successfully marked read. - 400: Bad Request status code if the app name is invalid. - 403: Forbidden status code if the user is not authenticated. - 404: Not Found status code if the notification was not found.
- permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
- openedx.core.djangoapps.notifications.views.preference_update_from_encrypted_username_view(request, *args, **kwargs)#
View to update user preferences from encrypted username and patch. username and patch must be string