lms.djangoapps.discussion package

Contents

lms.djangoapps.discussion package#

Subpackages#

Submodules#

lms.djangoapps.discussion.apps module#

Discussion Application Configuration

Signal handlers are connected here.

class lms.djangoapps.discussion.apps.DiscussionConfig(app_name, app_module)#

Bases: AppConfig

Application Configuration for Discussion.

name = 'lms.djangoapps.discussion'#
plugin_app = {'settings_config': {'cms.djangoapp': {'common': {'relative_path': 'settings.common'}}, 'lms.djangoapp': {'common': {'relative_path': 'settings.common'}}}, 'url_config': {'lms.djangoapp': {'app_name': 'lms.djangoapps.discussion', 'namespace': '', 'regex': '^courses/(?P<course_id>[^/+]+(/|\\+)[^/+]+(/|\\+)[^/?]+)/discussion/forum/', 'relative_path': 'urls'}}}#
ready()#

Connect handlers to send notifications about discussions.

lms.djangoapps.discussion.exceptions module#

Custom exceptions raised by Discussion API.

exception lms.djangoapps.discussion.exceptions.TeamDiscussionHiddenFromUserException#

Bases: BaseException

This is the exception raised when a user is not permitted to view the discussion thread

lms.djangoapps.discussion.plugins module#

Views handling read (GET) requests for the Discussion tab and inline discussions.

class lms.djangoapps.discussion.plugins.DiscussionTab(tab_dict)#

Bases: TabFragmentViewMixin, EnrolledTab

A tab for the forums.

body_class = 'discussion'#
fragment_view_name = 'lms.djangoapps.discussion.views.DiscussionBoardFragmentView'#
is_default = False#
classmethod is_enabled(course, user=None)#

Returns true if this course tab is enabled in the course.

Parameters:
  • course (CourseBlock) – the course using the feature

  • user (User) – an optional user interacting with the course (defaults to None)

is_hideable = True#

Returns a function that returns the course tab’s URL.

online_help_token = 'discussions'#
priority = 40#
title = 'Discussion'#
type = 'discussion'#
view_name = 'forum_form_discussion'#

lms.djangoapps.discussion.rate_limit module#

Contains all code related to rate limit

lms.djangoapps.discussion.rate_limit.is_content_creation_rate_limited(request, course_key=None, increment=True)#

Check if the request is rate limited for content creation in discussions.

lms.djangoapps.discussion.rate_limit.is_rate_limited(request, group, key='user', rate='10/m', method=(None,), increment=True, course_key=None)#

Check if the request is rate limited :param request: The HTTP request object. :param group: The group to which the rate limit applies :param key: The key to identify (user or ip). :param rate: The rate limit (default is ‘10/m’ - 10 requests per minute). :param method: The HTTP method to check (default is ‘POST’). :param increment: Whether to increment the rate limit counter (default is True). :param course_key: The course key for which the rate limit is applied (optional).

Returns:

True if the request is rate limited, False otherwise.

Return type:

bool

lms.djangoapps.discussion.tasks module#

Defines asynchronous celery task for sending email notification (through edx-ace) pertaining to new discussion forum comments.

class lms.djangoapps.discussion.tasks.CommentNotification(*args, **kwargs)#

Bases: BaseMessageType

Notify discussion participants of new comments.

class lms.djangoapps.discussion.tasks.ReportedContentNotification(*args, **kwargs)#

Bases: BaseMessageType

class lms.djangoapps.discussion.tasks.ResponseNotification(*args, **kwargs)#

Bases: BaseMessageType

lms.djangoapps.discussion.toggles module#

Discussions feature toggles

lms.djangoapps.discussion.toggles_utils module#

Utils for Discussions feature toggles

lms.djangoapps.discussion.toggles_utils.reported_content_email_notification_enabled(course_key)#

Checks for relevant flag and setting and returns boolean for reported content email notification for course

lms.djangoapps.discussion.urls module#

Forum urls for the django_comment_client.

lms.djangoapps.discussion.views module#

Views handling read (GET) requests for the Discussion tab and inline discussions.

class lms.djangoapps.discussion.views.DiscussionBoardFragmentView(**kwargs)#

Bases: EdxFragmentView

Component implementation of the discussion board.

css_dependencies()#

Returns list of CSS files that this view depends on.

The helper function that it uses to obtain the list of CSS files works in conjunction with the Django pipeline to ensure that in development mode the files are loaded individually, but in production just the single bundle is loaded.

js_dependencies()#

Returns list of JS files that this view depends on.

The helper function that it uses to obtain the list of JS files works in conjunction with the Django pipeline to ensure that in development mode the files are loaded individually, but in production just the single bundle is loaded.

render_to_fragment(request, course_id=None, discussion_id=None, thread_id=None, profile_page_context=None, **kwargs)#

Render the discussion board to a fragment.

Parameters:
  • request – The Django request.

  • course_id – The id of the course in question.

  • discussion_id – An optional discussion ID to be focused upon.

  • thread_id – An optional ID of the thread to be shown.

Returns:

The fragment representing the discussion board

Return type:

Fragment

vendor_js_dependencies()#

Returns list of vendor JS files that this view depends on.

The helper function that it uses to obtain the list of vendor JS files works in conjunction with the Django pipeline to ensure that in development mode the files are loaded individually, but in production just the single bundle is loaded.

lms.djangoapps.discussion.views.course_discussions_settings_handler(request, course_key_string)#

The restful handler for divided discussion setting requests. Requires JSON. This will raise 404 if user is not staff. GET

Returns the JSON representation of divided discussion settings for the course.

PATCH

Updates the divided discussion settings for the course. Returns the JSON representation of updated settings.

lms.djangoapps.discussion.views.create_user_profile_context(request, course_key, user_id)#

Generate a context dictionary for the user profile.

lms.djangoapps.discussion.views.discussion_topics(request, course_key_string)#

The handler for divided discussion categories requests. This will raise 404 if user is not staff.

Returns the JSON representation of discussion topics w.r.t categories for the course.

Example

>>> example = {
>>>               "course_wide_discussions": {
>>>                   "entries": {
>>>                       "General": {
>>>                           "sort_key": "General",
>>>                           "is_divided": True,
>>>                           "id": "i4x-edx-eiorguegnru-course-foobarbaz"
>>>                       }
>>>                   }
>>>                   "children": ["General", "entry"]
>>>               },
>>>               "inline_discussions" : {
>>>                   "subcategories": {
>>>                       "Getting Started": {
>>>                           "subcategories": {},
>>>                           "children": [
>>>                               ["Working with Videos", "entry"],
>>>                               ["Videos on edX", "entry"]
>>>                           ],
>>>                           "entries": {
>>>                               "Working with Videos": {
>>>                                   "sort_key": None,
>>>                                   "is_divided": False,
>>>                                   "id": "d9f970a42067413cbb633f81cfb12604"
>>>                               },
>>>                               "Videos on edX": {
>>>                                   "sort_key": None,
>>>                                   "is_divided": False,
>>>                                   "id": "98d8feb5971041a085512ae22b398613"
>>>                               }
>>>                           }
>>>                       },
>>>                       "children": ["Getting Started", "subcategory"]
>>>                   },
>>>               }
>>>          }
lms.djangoapps.discussion.views.followed_threads(request, course_key, user_id)#

Ajax-only endpoint retrieving the threads followed by a specific user.

lms.djangoapps.discussion.views.forum_form_discussion(request, course_key)#

Renders the main Discussion page, potentially filtered by a search query

lms.djangoapps.discussion.views.get_threads(request, course, user_info, discussion_id=None, per_page=20)#

This may raise an appropriate subclass of cc.utils.CommentClientError if something goes wrong, or ValueError if the group_id is invalid.

Parameters:
  • request (WSGIRequest) – The user request.

  • course (CourseBlockWithMixins) – The course object.

  • user_info (dict) – The comment client User object as a dict.

  • discussion_id (unicode) – Optional discussion id/commentable id for context.

  • per_page (int) – Optional number of threads per page.

Returns:

A tuple of the list of threads and a dict of the

query parameters used for the search.

Return type:

(tuple of list, dict)

lms.djangoapps.discussion.views.inline_discussion(request, course_key, discussion_id)#

Renders JSON for DiscussionModules

lms.djangoapps.discussion.views.is_course_staff(course_key: CourseKey, user: User)#

Check if user has course instructor or course staff role.

lms.djangoapps.discussion.views.is_privileged_user(course_key: CourseKey, user: User)#

Returns True if user has one of following course role Administrator, Moderator, Group Moderator, Community TA, or Global Staff.

lms.djangoapps.discussion.views.make_course_settings(course, user, include_category_map=True)#

Generate a JSON-serializable model for course settings, which will be used to initialize a DiscussionCourseSettings object on the client.

lms.djangoapps.discussion.views.redirect_forum_url_to_new_mfe(request, course_id)#

Returns the redirect link when user opens default discussion homepage

lms.djangoapps.discussion.views.redirect_thread_url_to_new_mfe(request, course_id, thread_id)#

Returns MFE url of the thread if the user is not privileged

lms.djangoapps.discussion.views.single_thread(request, course_key, discussion_id, thread_id)#

Renders a response to display a single discussion thread. This could either be a page refresh after navigating to a single thread, a direct link to a single thread, or an AJAX call from the discussions UI loading the responses/comments for a single thread.

Depending on the HTTP headers, we’ll adjust our response accordingly.

lms.djangoapps.discussion.views.use_bulk_ops(view_func)#

Wraps internal request handling inside a modulestore bulk op, significantly reducing redundant database calls. Also converts the course_id parsed from the request uri to a CourseKey before passing to the view.

lms.djangoapps.discussion.views.user_profile(request, course_key, user_id)#

Renders a response to display the user profile page (shown after clicking on a post author’s username).

Module contents#