lms.djangoapps.edxnotes package#

Submodules#

lms.djangoapps.edxnotes.api_urls module#

API URLs for EdxNotes

lms.djangoapps.edxnotes.decorators module#

Decorators related to edXNotes.

lms.djangoapps.edxnotes.decorators.edxnotes(cls)#

Decorator that makes components annotatable.

lms.djangoapps.edxnotes.exceptions module#

Exceptions related to EdxNotes.

exception lms.djangoapps.edxnotes.exceptions.EdxNotesParseError#

Bases: Exception

An exception that is raised whenever we have issues with data parsing.

exception lms.djangoapps.edxnotes.exceptions.EdxNotesServiceUnavailable#

Bases: Exception

An exception that is raised whenever EdxNotes service is unavailable.

lms.djangoapps.edxnotes.helpers module#

Helper methods related to EdxNotes.

class lms.djangoapps.edxnotes.helpers.NoteJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)#

Bases: JSONEncoder

Custom JSON encoder that encode datetime objects to appropriate time strings.

default(obj)#

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return super().default(o)
lms.djangoapps.edxnotes.helpers.construct_pagination_urls(request, course_id, api_next_url, api_previous_url)#

Construct next and previous urls for LMS. api_next_url and api_previous_url are returned from notes api but we need to transform them according to LMS notes views by removing and replacing extra information.

Parameters:
  • request – HTTP request object

  • course_id – course id

  • api_next_url – notes api next url

  • api_previous_url – notes api previous url

Returns:

lms notes next url previous_url: lms notes previous url

Return type:

next_url

lms.djangoapps.edxnotes.helpers.delete_all_notes_for_user(user)#

helper method to delete all notes for a user, as part of GDPR compliance

Parameters:

user – The user object associated with the deleted notes

Returns:

response (requests) object

Raises:

EdxNotesServiceUnavailable - when notes api is not found/misconfigured.

lms.djangoapps.edxnotes.helpers.generate_uid()#

Generates unique id.

lms.djangoapps.edxnotes.helpers.get_block_context(course, block)#

Returns dispay_name and url for the parent block.

lms.djangoapps.edxnotes.helpers.get_course_position(course_block)#

Return the user’s current place in the course.

If this is the user’s first time, leads to COURSE/SECTION/SUBSECTION. If this isn’t the users’s first time, leads to COURSE/SECTION.

If there is no current position in the course or subsection, then selects the first child.

lms.djangoapps.edxnotes.helpers.get_edxnotes_id_token(user)#

Returns generated ID Token for edxnotes.

lms.djangoapps.edxnotes.helpers.get_endpoint(api_url, path='')#

Returns edx-notes-api endpoint.

Parameters:
  • api_url (str) – base url to the notes api

  • path (str) – path to the resource

Returns:

full endpoint to the notes api

Return type:

str

lms.djangoapps.edxnotes.helpers.get_index(usage_key, children)#

Returns an index of the child with usage_key.

lms.djangoapps.edxnotes.helpers.get_internal_endpoint(path='')#

Get the full path to a resource on the private notes API.

lms.djangoapps.edxnotes.helpers.get_notes(request, course, page=1, page_size=25, text=None)#

Returns paginated list of notes for the user.

Parameters:
  • request – HTTP request object

  • course – Course block

  • page – requested or default page number

  • page_size – requested or default page size

  • text – text to search. If None then return all results for the current logged in user.

Returns:

start: start of the current page current_page: current page number next: url for next page previous: url for previous page count: total number of notes available for the sent query num_pages: number of pages available results: list with notes info dictionary. each item in this list will be a dict

Return type:

Paginated dictionary with these key

lms.djangoapps.edxnotes.helpers.get_public_endpoint(path='')#

Get the full path to a resource on the public notes API.

lms.djangoapps.edxnotes.helpers.get_token_url(course_id)#

Returns token url for the course.

lms.djangoapps.edxnotes.helpers.is_feature_enabled(course, user)#

Returns True if Student Notes feature is enabled for the course, False otherwise.

lms.djangoapps.edxnotes.helpers.preprocess_collection(user, course, collection)#

Prepare collection(notes_list) provided by edx-notes-api for rendering in a template:

add information about ancestor blocks, convert “updated” to date

Raises:

ItemNotFoundError - when appropriate block is not found.

lms.djangoapps.edxnotes.helpers.send_request(user, course_id, page, page_size, path='', text=None)#

Sends a request to notes api with appropriate parameters and headers.

Parameters:
  • user – Current logged in user

  • course_id – Course id

  • page – requested or default page number

  • page_size – requested or default page size

  • pathsearch or annotations. This is used to calculate notes api endpoint.

  • text – text to search.

Returns:

Response received from notes api

lms.djangoapps.edxnotes.plugins module#

Registers the “edX Notes” feature for the edX platform.

class lms.djangoapps.edxnotes.plugins.EdxNotesCourseApp#

Bases: CourseApp

Course app for edX notes.

app_id: str = 'edxnotes'#
description: str = 'Allow learners to highlight passages and make notes right in the course.'#
classmethod get_allowed_operations(course_key: CourseKey, user: User | None = None) Dict[str, bool]#

Returns allowed operations for edxnotes app.

classmethod is_available(course_key: CourseKey) bool#

EdX notes availability is currently globally controlled via a feature setting.

classmethod is_enabled(course_key: CourseKey) bool#

Get enabled/disabled status from modulestore.

name: str = 'Notes'#
classmethod set_enabled(course_key: CourseKey, enabled: bool, user: User) bool#

Enable/disable edxnotes in the modulestore.

class lms.djangoapps.edxnotes.plugins.EdxNotesTab(tab_dict)#

Bases: EnrolledTab

The representation of the edX Notes course tab type.

classmethod is_enabled(course, user=None)#

Returns true if the edX Notes feature is enabled in the course.

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

  • user (User) – the user interacting with the course

priority = 50#
title = 'Notes'#
type = 'edxnotes'#
view_name = 'edxnotes'#

lms.djangoapps.edxnotes.urls module#

URLs for EdxNotes.

lms.djangoapps.edxnotes.views module#

Views related to EdxNotes.

class lms.djangoapps.edxnotes.views.RetireUserView(**kwargs)#

Bases: APIView

Use Cases

A superuser or the user with the username specified by settings.RETIREMENT_SERVICE_WORKER_USERNAME can “retire” the user’s data from the edx-notes-api (aka. Edxnotes) service, which will delete all notes (aka. annotations) the user has made.

Example Requests

  • POST /api/edxnotes/v1/retire_user/ {

    “username”: “an_original_username”

    }

Example Response

  • HTTP 204 with empty body, indicating success.

  • HTTP 404 with empty body. This can happen when: - The requested user does not exist in the retirement queue.

  • HTTP 405 (Method Not Allowed) with error message. This can happen when: - RetirementStateError is thrown: the user is currently in a retirement state which cannot be acted on, such

    as a terminal or completed state.

  • HTTP 500 with error message. This can happen when: - EdxNotesServiceUnavailable is thrown: the edx-notes-api IDA is not available.

permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>, <class 'openedx.core.djangoapps.user_api.accounts.permissions.CanRetireUser'>)#
post(request)#

Implements the retirement endpoint.

lms.djangoapps.edxnotes.views.edxnotes(request, course_id)#

Displays the EdxNotes page.

Parameters:
  • request – HTTP request object

  • course_id – course id

Returns:

Rendered HTTP response.

lms.djangoapps.edxnotes.views.edxnotes_visibility(request, course_id)#

Handle ajax call from “Show notes” checkbox.

lms.djangoapps.edxnotes.views.get_token(request, course_id)#

Get JWT ID-Token, in case you need new one.

lms.djangoapps.edxnotes.views.notes(request, course_id)#

Notes view to handle list and search requests.

Query parameters:

page: page number to get page_size: number of items in the page text: text string to search. If text param is missing then get all the

notes for the current user for this course else get only those notes which contain the text value.

Parameters:
  • request – HTTP request object

  • course_id – course id

Returns:

Paginated response as JSON. A sample response is below. {

”count”: 101, “num_pages”: 11, “current_page”: 1, “results”: [

{
“chapter”: {

“index”: 4, “display_name”: “About Exams and Certificates”, “location”: “i4x://org/course/category/name@revision”, “children”: [

”i4x://org/course/category/name@revision”

]

}, “updated”: “Dec 09, 2015 at 09:31 UTC”, “tags”: [“shadow”,”oil”], “quote”: “foo bar baz”, “section”: {

”display_name”: “edX Exams”, “location”: “i4x://org/course/category/name@revision”, “children”: [

”i4x://org/course/category/name@revision”, “i4x://org/course/category/name@revision”,

]

}, “created”: “2015-12-09T09:31:17.338305Z”, “ranges”: [

{

“start”: “/div[1]/p[1]”, “end”: “/div[1]/p[1]”, “startOffset”: 0, “endOffset”: 6

}

], “user”: “50cf92f9a3d8489df95e583549b919df”, “text”: “first angry height hungry structure”, “course_id”: “edx/DemoX/Demo”, “id”: “1231”, “unit”: {

”url”: “/courses/edx%2FDemoX%2FDemo/courseware/1414ffd5143b4b508f739b563ab468b7/workflow/1”, “display_name”: “EdX Exams”, “location”: “i4x://org/course/category/name@revision”

}, “usage_id”: “i4x://org/course/category/name@revision”

} ],

”next”: “http://0.0.0.0:8000/courses/edx%2FDemoX%2FDemo/edxnotes/notes/?page=2&page_size=10”, “start”: 0, “previous”: null

}

Module contents#