lms.djangoapps.course_blocks.transformers package#
Submodules#
lms.djangoapps.course_blocks.transformers.access_denied_filter module#
Access Denied Message Filter Transformer implementation.
- class lms.djangoapps.course_blocks.transformers.access_denied_filter.AccessDeniedMessageFilterTransformer#
Bases:
BlockStructureTransformerA transformer that removes any block from the course that has an authorization_denial_reason or an authorization_denial_message.
- 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; same identifier used in setup.py.
- transform(usage_info, block_structure)#
Transforms the given block_structure for the given usage_info, assuming the block_structure contains cached data from a prior call to the collect method of the latest version of the Transformer.
No access to the modulestore nor instantiation of xBlocks should be performed during the execution of this method. However, accesses to user-specific data (outside of the modulestore and not via xBlocks) is permitted in order to apply the transform for the given usage_info.
Note: The root of the given block_structure is not necessarily the same as the root of the block_structure passed to the prior collect method. The collect method is given the top-most root of the structure, while the transform method may be called upon any sub-structure or even a single block within the originally collected structure.
A Transformer may choose to remove entire sub-structures during the transform method and may do so using the remove_block and filter_with_removal methods.
Amongst the many methods available for a block_structure, the following methods are commonly used during transforms:
get_xblock_field get_transformer_data get_transformer_block_field remove_block_traversal filter_with_removal filter_topological_traversal topological_traversal post_order_traversal
- Parameters:
usage_info (any negotiated type) – that is passed to the block_structure and forwarded to all requested Transformers in order to apply a usage-specific transform. For example, an instance of usage_info would contain a user object for which the transform should be applied.
block_structure (BlockStructureBlockData) – block structure, with already collected data for the transformer, that is to be transformed in place.
lms.djangoapps.course_blocks.transformers.library_content module#
Content Library Transformer.
- class lms.djangoapps.course_blocks.transformers.library_content.ContentLibraryOrderTransformer#
Bases:
BlockStructureTransformerA transformer that manipulates the block structure by modifying the order of the selected blocks within a library_content block to match the order of the selections made by the ContentLibraryTransformer or the corresponding XBlock. So this transformer requires the selections for the randomized content block to be already made either by the ContentLibraryTransformer or the XBlock.
Staff users are not exempted from library content pathways.
- 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; same identifier used in setup.py
- transform(usage_info, block_structure)#
Transforms the order of the children of the randomized content block to match the order of the selections made and stored in the XBlock ‘selected’ field.
- class lms.djangoapps.course_blocks.transformers.library_content.ContentLibraryTransformer#
Bases:
FilteringTransformerMixin,BlockStructureTransformerA transformer that manipulates the block structure by removing all blocks within a library_content block to which a user should not have access.
Staff users are not to be exempted from library content pathways.
- 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; same identifier used in setup.py.
- transform_block_filters(usage_info, block_structure)#
This is an alternative to the standard transform method.
Returns a list of filter functions to be used for filtering out any unwanted blocks in the given block_structure.
In addition to the commonly used methods listed above, the following methods are commonly used by implementations of transform_block_filters:
create_universal_filter create_removal_filter
Note: Transformers that implement this alternative should be independent of all other registered transformers as they may not be applied in the order in which they were listed in the registry.
- Parameters:
usage_info (any negotiated type) – that is passed to the block_structure and forwarded to all requested Transformers in order to apply a usage-specific transform. For example, an instance of usage_info would contain a user object for which the transform should be applied.
block_structure (BlockStructureBlockData) – block structure, with already collected data for the transformer, that is to be transformed in place.
lms.djangoapps.course_blocks.transformers.load_override_data module#
Load Override Data Transformer
- class lms.djangoapps.course_blocks.transformers.load_override_data.OverrideDataTransformer(user)#
Bases:
BlockStructureTransformerA transformer that load override data in xblock.
- 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; same identifier used in setup.py.
- transform(usage_info, block_structure)#
loads override data into blocks
- lms.djangoapps.course_blocks.transformers.load_override_data.override_xblock_fields(course_key, location_list, block_structure, user_id)#
loads override data of block
- Parameters:
course_key (CourseLocator) – course locator object
location_list (List<UsageKey>) – list of usage key of all blocks
block_structure (BlockStructure) – block structure class
user_id (int) – User id
lms.djangoapps.course_blocks.transformers.split_test module#
Split Test Block Transformer
- class lms.djangoapps.course_blocks.transformers.split_test.SplitTestTransformer#
Bases:
FilteringTransformerMixin,BlockStructureTransformerA nested transformer of the UserPartitionTransformer that honors the block structure pathways created by split_test blocks.
To avoid code duplication, the implementation transforms its block access representation to the representation used by user_partitions. Namely, the ‘group_id_to_child’ field on a split_test block is transformed into the, now standard, ‘group_access’ fields in the split_test block’s children.
The implementation therefore relies on the UserPartitionTransformer to actually enforce the access using the ‘user_partitions’ and ‘group_access’ fields.
- 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; same identifier used in setup.py.
- transform_block_filters(usage_info, block_structure)#
Mutates block_structure based on the given usage_info.
lms.djangoapps.course_blocks.transformers.start_date module#
Start Date Transformer implementation.
- class lms.djangoapps.course_blocks.transformers.start_date.StartDateTransformer#
Bases:
FilteringTransformerMixin,BlockStructureTransformerA transformer that enforces the ‘start’ and ‘days_early_for_beta’ fields on blocks by removing blocks from the block structure for which the user does not have access. The ‘start’ field on a block is percolated down to its descendants, so that all blocks enforce the ‘start’ field from their ancestors. The assumed ‘start’ value for a block is then the maximum of its parent and its own.
For a block with multiple parents, the assumed parent start date value is a computed minimum of the start dates of all its parents. So as long as one parent chain allows access, the block has access.
Staff users are exempted from visibility rules.
- MERGED_START_DATE = 'merged_start_date'#
- 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; same identifier used in setup.py.
- transform_block_filters(usage_info, block_structure)#
This is an alternative to the standard transform method.
Returns a list of filter functions to be used for filtering out any unwanted blocks in the given block_structure.
In addition to the commonly used methods listed above, the following methods are commonly used by implementations of transform_block_filters:
create_universal_filter create_removal_filter
Note: Transformers that implement this alternative should be independent of all other registered transformers as they may not be applied in the order in which they were listed in the registry.
- Parameters:
usage_info (any negotiated type) – that is passed to the block_structure and forwarded to all requested Transformers in order to apply a usage-specific transform. For example, an instance of usage_info would contain a user object for which the transform should be applied.
block_structure (BlockStructureBlockData) – block structure, with already collected data for the transformer, that is to be transformed in place.
lms.djangoapps.course_blocks.transformers.user_partitions module#
User Partitions Transformer
- class lms.djangoapps.course_blocks.transformers.user_partitions.UserPartitionTransformer#
Bases:
BlockStructureTransformerA transformer that enforces the group access rules on course blocks, by honoring their user_partitions and group_access fields, and removing all blocks in the block structure to which the user does not have group access.
Staff users are not exempted from user partition pathways.
- READ_VERSION = 1#
- WRITE_VERSION = 1#
- classmethod collect(block_structure)#
Computes any information for each XBlock that’s necessary to execute this transformer’s transform method.
- Parameters:
block_structure (BlockStructureCollectedData)
- classmethod name()#
Unique identifier for the transformer’s class; same identifier used in setup.py.
- transform(usage_info, block_structure)#
Transforms the given block_structure for the given usage_info, assuming the block_structure contains cached data from a prior call to the collect method of the latest version of the Transformer.
No access to the modulestore nor instantiation of xBlocks should be performed during the execution of this method. However, accesses to user-specific data (outside of the modulestore and not via xBlocks) is permitted in order to apply the transform for the given usage_info.
Note: The root of the given block_structure is not necessarily the same as the root of the block_structure passed to the prior collect method. The collect method is given the top-most root of the structure, while the transform method may be called upon any sub-structure or even a single block within the originally collected structure.
A Transformer may choose to remove entire sub-structures during the transform method and may do so using the remove_block and filter_with_removal methods.
Amongst the many methods available for a block_structure, the following methods are commonly used during transforms:
get_xblock_field get_transformer_data get_transformer_block_field remove_block_traversal filter_with_removal filter_topological_traversal topological_traversal post_order_traversal
- Parameters:
usage_info (any negotiated type) – that is passed to the block_structure and forwarded to all requested Transformers in order to apply a usage-specific transform. For example, an instance of usage_info would contain a user object for which the transform should be applied.
block_structure (BlockStructureBlockData) – block structure, with already collected data for the transformer, that is to be transformed in place.
lms.djangoapps.course_blocks.transformers.utils module#
Common Helper utilities for transformers
- lms.djangoapps.course_blocks.transformers.utils.collect_merged_boolean_field(block_structure, transformer, xblock_field_name, merged_field_name)#
Collects a boolean xBlock field of name xblock_field_name for the given block_structure and transformer. The boolean value is percolated down the hierarchy of the block_structure and stored as a value of merged_field_name in the block_structure.
Assumes that the boolean field is False, by default. So, the value is ANDed across all parents for blocks with multiple parents and ORed across all ancestors down a single hierarchy chain.
- lms.djangoapps.course_blocks.transformers.utils.collect_merged_date_field(block_structure, transformer, xblock_field_name, merged_field_name, default_date, func_merge_parents=<built-in function min>, func_merge_ancestors=<built-in function max>)#
Collects a date xBlock field of name xblock_field_name for the given block_structure and transformer. The date value is percolated down the hierarchy of the block_structure and stored as a value of merged_field_name in the block_structure.
- lms.djangoapps.course_blocks.transformers.utils.collect_unioned_set_field(block_structure, transformer, merged_field_name, filter_by)#
Recursively union a set field on the block structure.
If a block matches filter_by, it will be added to the result set. This (potentially empty) set is unioned with the sets contained in merged_field_name for all parents of the block.
This set union operation takes place during a topological traversal of the block_structure, so all sets are inherited by descendants.
- Parameters:
block_structure – BlockStructure to traverse
transformer – transformer that will be used for get_ and set_transformer_block_field
merged_field_name – name of the field to store
filter_by – a unary lambda that returns true if a given block_key should be included in the result set
- lms.djangoapps.course_blocks.transformers.utils.get_field_on_block(block, field_name, default_value=None)#
Get the field value that is directly set on the xblock. Do not get the inherited value since field inheritance returns value from only a single parent chain (e.g., doesn’t take a union in DAGs).
lms.djangoapps.course_blocks.transformers.visibility module#
Visibility Transformer implementation.
- class lms.djangoapps.course_blocks.transformers.visibility.VisibilityTransformer#
Bases:
FilteringTransformerMixin,BlockStructureTransformerA transformer that enforces the visible_to_staff_only field on blocks by removing blocks from the block structure for which the user does not have access. The visible_to_staff_only field on a block is percolated down to its descendants, so that all blocks enforce the visibility settings from their ancestors.
For a block with multiple parents, access is denied only if visibility is denied for all its parents.
Staff users are exempted from visibility rules.
- MERGED_VISIBLE_TO_STAFF_ONLY = 'merged_visible_to_staff_only'#
- 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; same identifier used in setup.py.
- transform_block_filters(usage_info, block_structure)#
This is an alternative to the standard transform method.
Returns a list of filter functions to be used for filtering out any unwanted blocks in the given block_structure.
In addition to the commonly used methods listed above, the following methods are commonly used by implementations of transform_block_filters:
create_universal_filter create_removal_filter
Note: Transformers that implement this alternative should be independent of all other registered transformers as they may not be applied in the order in which they were listed in the registry.
- Parameters:
usage_info (any negotiated type) – that is passed to the block_structure and forwarded to all requested Transformers in order to apply a usage-specific transform. For example, an instance of usage_info would contain a user object for which the transform should be applied.
block_structure (BlockStructureBlockData) – block structure, with already collected data for the transformer, that is to be transformed in place.
Module contents#
Module container for all Course Block Access Transformers.