lms.djangoapps.course_api.blocks.transformers package

Contents

lms.djangoapps.course_api.blocks.transformers package#

Submodules#

lms.djangoapps.course_api.blocks.transformers.block_completion module#

Block Completion Transformer

class lms.djangoapps.course_api.blocks.transformers.block_completion.BlockCompletionTransformer#

Bases: BlockStructureTransformer

Keep track of the completion of each block within the block structure.

COMPLETE = 'complete'#
COMPLETION = 'completion'#
READ_VERSION = 1#
RESUME_BLOCK = 'resume_block'#
WRITE_VERSION = 1#
classmethod collect(block_structure)#

Collects and stores any xBlock and modulestore data into the block_structure that’s necessary for later execution of the transformer’s transform method. Transformers should store such data in the block_structure using the following methods:

set_transformer_data set_transformer_block_field request_xblock_fields

Transformers can call block_structure.request_xblock_fields for any common xBlock fields that should be collected by the framework.

Any full block tree traversals should be implemented in this collect phase, leaving the transform phase for fast and direct access to a sub-block. If a block’s transform output is dependent on its ancestors’ data, the ancestor’s data should be percolated down to the descendants. So when a (non-root) block is directly accessed in the transform, all of its relevant data is readily available (without needing to access its ancestors).

Traversals of the block_structure can be implemented using the following methods:

topological_traversal post_order_traversal

Parameters:

block_structure (BlockStructureModulestoreData) – block structure that is to be modified with collected data to be cached for the transformer.

classmethod get_block_completion(block_structure, block_key)#

Return the precalculated completion of a block within the block_structure:

Parameters:
  • block_structure – a BlockStructure instance

  • block_key – the key of the block whose completion we want to know

Returns:

float or None

Return type:

block_completion

mark_complete(complete_course_blocks, latest_complete_block_key, block_key, block_structure)#

Helper function to mark a block as ‘complete’ as dictated by complete_course_blocks (for problems) or all of a block’s children being complete. This also sets the ‘resume_block’ field as that is connected to the latest completed block.

Parameters:
  • complete_course_blocks – container of complete block keys

  • latest_complete_block_key – block key for the latest completed block.

  • block_key – A opaque_keys.edx.locator.BlockUsageLocator object

  • block_structure – A BlockStructureBlockData object

classmethod name()#

Unique identifier for the transformer’s class. It is used to identify the transformer’s cached data. So it should be unique and not conflict with other transformers. Consider using the same name that is used in the Transformer Registry. For example, for Stevedore, it is specified in the package configuration (pyproject.toml).

Once the transformer is in use and its data is cached, do not modify this name value without consideration of backward compatibility with previously collected data.

transform(usage_info, block_structure)#

Mutates block_structure adding three extra fields which contains block’s completion, complete status, and if the block is a resume_block, indicating it is the most recently completed block.

IMPORTANT!: There is a subtle, but important difference between ‘completion’ and ‘complete’ which are both set in this transformer: ‘completion’: Returns a percentile (0.0 - 1.0) of completion for a _problem_. This field will

be None for all other blocks that are not leaves and captured in BlockCompletion.

‘complete’: Returns a boolean indicating whether the block is complete. For problems, this will

be taken from a BlockCompletion 1.0 entry existing. For all other blocks, it will be marked True if all of the children of the block are all marked complete (this is calculated recursively)

lms.djangoapps.course_api.blocks.transformers.block_counts module#

Block Counts Transformer

class lms.djangoapps.course_api.blocks.transformers.block_counts.BlockCountsTransformer(block_types_to_count)#

Bases: BlockStructureTransformer

Keep a count of descendant blocks of the requested types

BLOCK_COUNTS = 'block_counts'#
READ_VERSION = 1#
WRITE_VERSION = 1#
classmethod collect(block_structure)#

Collects any information that’s necessary to execute this transformer’s transform method.

classmethod name()#

Unique identifier for the transformer’s class. It is used to identify the transformer’s cached data. So it should be unique and not conflict with other transformers. Consider using the same name that is used in the Transformer Registry. For example, for Stevedore, it is specified in the package configuration (pyproject.toml).

Once the transformer is in use and its data is cached, do not modify this name value without consideration of backward compatibility with previously collected data.

transform(usage_info, block_structure)#

Mutates block_structure based on the given usage_info.

lms.djangoapps.course_api.blocks.transformers.block_depth module#

Block Depth Transformer

class lms.djangoapps.course_api.blocks.transformers.block_depth.BlockDepthTransformer(requested_depth=None)#

Bases: BlockStructureTransformer

Keep track of the depth of each block within the block structure. In case of multiple paths to a given node (in a DAG), use the shallowest depth.

BLOCK_DEPTH = 'block_depth'#
READ_VERSION = 1#
WRITE_VERSION = 1#
classmethod get_block_depth(block_structure, block_key)#

Return the precalculated depth of a block within the block_structure:

Parameters:
  • block_structure – a BlockStructure instance

  • block_key – the key of the block whose depth we want to know

Returns:

int

classmethod name()#

Unique identifier for the transformer’s class. It is used to identify the transformer’s cached data. So it should be unique and not conflict with other transformers. Consider using the same name that is used in the Transformer Registry. For example, for Stevedore, it is specified in the package configuration (pyproject.toml).

Once the transformer is in use and its data is cached, do not modify this name value without consideration of backward compatibility with previously collected data.

transform(usage_info, block_structure)#

Mutates block_structure based on the given usage_info.

lms.djangoapps.course_api.blocks.transformers.blocks_api module#

Blocks API Transformer

class lms.djangoapps.course_api.blocks.transformers.blocks_api.BlocksAPITransformer(block_types_to_count, requested_student_view_data, depth=None, nav_depth=None)#

Bases: BlockStructureTransformer

Umbrella transformer that contains all the transformers needed by the Course Blocks API.

Contained Transformers (processed in this order):

StudentViewTransformer BlockCountsTransformer BlockDepthTransformer BlockNavigationTransformer VideoBlockStreamPriorityTransformer ExtraFieldsTransformer

Note

  • BlockDepthTransformer must be executed before BlockNavigationTransformer.

  • StudentViewTransformer must be executed before VideoBlockURLTransformer.

READ_VERSION = 1#
STUDENT_VIEW_DATA = 'student_view_data'#
STUDENT_VIEW_MULTI_DEVICE = 'student_view_multi_device'#
WRITE_VERSION = 1#
classmethod collect(block_structure)#

Collects any information that’s necessary to execute this transformer’s transform method.

classmethod name()#

Unique identifier for the transformer’s class. It is used to identify the transformer’s cached data. So it should be unique and not conflict with other transformers. Consider using the same name that is used in the Transformer Registry. For example, for Stevedore, it is specified in the package configuration (pyproject.toml).

Once the transformer is in use and its data is cached, do not modify this name value without consideration of backward compatibility with previously collected data.

transform(usage_info, block_structure)#

Mutates block_structure based on the given usage_info.

lms.djangoapps.course_api.blocks.transformers.extra_fields module#

Extra Fields Transformer

class lms.djangoapps.course_api.blocks.transformers.extra_fields.ExtraFieldsTransformer#

Bases: BlockStructureTransformer

A configurable transformer that adds additional XBlock fields to the course blocks API.

Extra fields must be specified using the “COURSE_BLOCKS_API_EXTRA_FIELDS” LMS Django settings variable. Open edX instances can use this to make additional XBlock fields available via the course blocks API, that aren’t otherwise included by default.

READ_VERSION = 1#
WRITE_VERSION = 1#
classmethod collect(block_structure)#

Collects any information that’s necessary to execute this transformer’s transform method.

classmethod get_requested_extra_fields()#

Returns the names of the requested extra fields

classmethod name()#

Unique identifier for the transformer’s class. It is used to identify the transformer’s cached data. So it should be unique and not conflict with other transformers. Consider using the same name that is used in the Transformer Registry. For example, for Stevedore, it is specified in the package configuration (pyproject.toml).

Once the transformer is in use and its data is cached, do not modify this name value without consideration of backward compatibility with previously collected data.

transform(usage_info, block_structure)#

Mutates block_structure based on the given usage_info.

lms.djangoapps.course_api.blocks.transformers.milestones module#

Milestones Transformer

class lms.djangoapps.course_api.blocks.transformers.milestones.MilestonesAndSpecialExamsTransformer(include_special_exams=True, include_gated_sections=True)#

Bases: BlockStructureTransformer

A transformer that handles both milestones and special (timed) exams.

It includes or excludes all unfulfilled milestones from the student view based on the value of include_gated_sections. # pylint: disable=line-too-long

An entrance exam is considered a milestone, and is not considered a “special exam”.

It also includes or excludes all special (timed) exams (timed, proctored, practice proctored) in/from the student view, based on the value of include_special_exams.

READ_VERSION = 1#
WRITE_VERSION = 1#
add_special_exam_info(block_key, block_structure, usage_info)#

For special exams, add the special exam information to the course blocks.

classmethod collect(block_structure)#

Computes any information for each XBlock that’s necessary to execute this transformer’s transform method.

Parameters:

block_structure (BlockStructureCollectedData)

static gated_by_required_content(block_key, block_structure, required_content)#

Returns True if the current block associated with the block_key should be gated by the given required_content. Returns False otherwise.

static get_required_content(usage_info, block_structure)#

Get the required content for the course.

This takes into account if the user can skip the entrance exam.

static has_pending_milestones_for_user(block_key, usage_info)#

Test whether the current user has any unfulfilled milestones preventing them from accessing this block.

static is_special_exam(block_key, block_structure)#

Test whether the block is a special exam.

classmethod name()#

Unique identifier for the transformer’s class. It is used to identify the transformer’s cached data. So it should be unique and not conflict with other transformers. Consider using the same name that is used in the Transformer Registry. For example, for Stevedore, it is specified in the package configuration (pyproject.toml).

Once the transformer is in use and its data is cached, do not modify this name value without consideration of backward compatibility with previously collected data.

transform(usage_info, block_structure)#

Modify block structure according to the behavior of milestones and special exams.

lms.djangoapps.course_api.blocks.transformers.navigation module#

TODO

class lms.djangoapps.course_api.blocks.transformers.navigation.BlockNavigationTransformer(nav_depth)#

Bases: BlockStructureTransformer

Creates a table of contents for the course.

Prerequisites: BlockDepthTransformer must be run before this in the transform phase.

BLOCK_NAVIGATION = 'block_nav'#
BLOCK_NAVIGATION_FOR_CHILDREN = 'children_block_nav'#
READ_VERSION = 1#
WRITE_VERSION = 1#
classmethod collect(block_structure)#

Collects any information that’s necessary to execute this transformer’s transform method.

classmethod name()#

Unique identifier for the transformer’s class. It is used to identify the transformer’s cached data. So it should be unique and not conflict with other transformers. Consider using the same name that is used in the Transformer Registry. For example, for Stevedore, it is specified in the package configuration (pyproject.toml).

Once the transformer is in use and its data is cached, do not modify this name value without consideration of backward compatibility with previously collected data.

transform(usage_info, block_structure)#

Mutates block_structure based on the given usage_info.

class lms.djangoapps.course_api.blocks.transformers.navigation.DescendantList#

Bases: object

Contain

lms.djangoapps.course_api.blocks.transformers.student_view module#

Student View Transformer

class lms.djangoapps.course_api.blocks.transformers.student_view.StudentViewTransformer(requested_student_view_data=None)#

Bases: BlockStructureTransformer

Only show information that is appropriate for a learner

READ_VERSION = 1#
STUDENT_VIEW_DATA = 'student_view_data'#
STUDENT_VIEW_MULTI_DEVICE = 'student_view_multi_device'#
WRITE_VERSION = 1#
classmethod collect(block_structure)#

Collect student_view_multi_device and student_view_data values for each block

classmethod name()#

Unique identifier for the transformer’s class. It is used to identify the transformer’s cached data. So it should be unique and not conflict with other transformers. Consider using the same name that is used in the Transformer Registry. For example, for Stevedore, it is specified in the package configuration (pyproject.toml).

Once the transformer is in use and its data is cached, do not modify this name value without consideration of backward compatibility with previously collected data.

transform(usage_info, block_structure)#

Mutates block_structure based on the given usage_info.

lms.djangoapps.course_api.blocks.transformers.video_stream_priority module#

Video block stream priority Transformer

class lms.djangoapps.course_api.blocks.transformers.video_stream_priority.VideoBlockStreamPriorityTransformer#

Bases: BlockStructureTransformer

Transformer to add stream priority for encoded_videos.

If DEPRECATE_YOUTUBE waffle flag is on for a course, Youtube videos have lowest priority. Else, the default priority for videos is as shown in DEFAULT_VIDEO_STREAM_PRIORITY below. With 0 being the highest stream priority. In case video_format not found in given, set stream_priority to -1.

DEFAULT_VIDEO_STREAM_PRIORITY = {'desktop_mp4': 4, 'desktop_webm': 5, 'fallback': 6, 'hls': 1, 'mobile_high': 3, 'mobile_low': 2, 'youtube': 0}#
DEPRECATE_YOUTUBE_VIDEO_STREAM_PRIORITY = {'desktop_mp4': 3, 'desktop_webm': 4, 'fallback': 5, 'hls': 0, 'mobile_high': 2, 'mobile_low': 1, 'youtube': 6}#
READ_VERSION = 1#
WRITE_VERSION = 1#
classmethod name()#

Unique identifier for the transformer’s class. It is used to identify the transformer’s cached data. So it should be unique and not conflict with other transformers. Consider using the same name that is used in the Transformer Registry. For example, for Stevedore, it is specified in the package configuration (pyproject.toml).

Once the transformer is in use and its data is cached, do not modify this name value without consideration of backward compatibility with previously collected data.

transform(usage_info, block_structure)#

Write all the video blocks’ stream priority.

For the encoded_videos dictionary, a field called stream_priority will be added to all the available video blocks. Client end can use this value to prioritise streaming for different video formats.

lms.djangoapps.course_api.blocks.transformers.video_urls module#

Video block URL Transformer

class lms.djangoapps.course_api.blocks.transformers.video_urls.VideoBlockURLTransformer#

Bases: BlockStructureTransformer

Transformer to re-write video urls for the encoded videos to server content from edx-video.

CDN_URL = 'https://edx-video.net'#
READ_VERSION = 1#
VIDEO_FORMAT_EXCEPTIONS = ['youtube', 'fallback']#
WRITE_VERSION = 1#
classmethod name()#

Unique identifier for the transformer’s class. It is used to identify the transformer’s cached data. So it should be unique and not conflict with other transformers. Consider using the same name that is used in the Transformer Registry. For example, for Stevedore, it is specified in the package configuration (pyproject.toml).

Once the transformer is in use and its data is cached, do not modify this name value without consideration of backward compatibility with previously collected data.

transform(usage_info, block_structure)#

Re-write all the video blocks’ encoded videos URLs.

For the encoded_videos dictionary, all the available video format URLs will be re-written to serve the videos from edx-video.net with YouTube and fallback URL as an exception. Fallback URL is an exception because when there is no video profile data in VAL, the user specified data from all_sources is taken, which can be URL from any CDN.

Module contents#