def _collect_explicit_graded(cls, block_structure): """ Collect the 'explicit_graded' field for every block. """ def _set_field(block_key, field_value): """ Sets the explicit graded field to the given value for the given block. """ block_structure.set_transformer_block_field( block_key, cls, cls.EXPLICIT_GRADED_FIELD_NAME, field_value) def _get_field(block_key): """ Gets the explicit graded field to the given value for the given block. """ return block_structure.get_transformer_block_field( block_key, cls, cls.EXPLICIT_GRADED_FIELD_NAME) block_types_to_ignore = {'course', 'chapter', 'sequential'} for block_key in block_structure.topological_traversal(): if block_key.block_type in block_types_to_ignore: _set_field(block_key, None) else: explicit_field_on_block = get_field_on_block( block_structure.get_xblock(block_key), 'graded') if explicit_field_on_block is not None: _set_field(block_key, explicit_field_on_block) else: values_from_parents = [ _get_field(parent) for parent in block_structure.get_parents(block_key) if parent.block_type not in block_types_to_ignore ] non_null_values_from_parents = [ value for value in values_from_parents if not None ] explicit_from_parents = functools_reduce( lambda x, y: x or y, non_null_values_from_parents, None) _set_field(block_key, explicit_from_parents)
def _collect_explicit_graded(cls, block_structure): """ Collect the 'explicit_graded' field for every block. """ def _set_field(block_key, field_value): """ Sets the explicit graded field to the given value for the given block. """ block_structure.set_transformer_block_field(block_key, cls, cls.EXPLICIT_GRADED_FIELD_NAME, field_value) def _get_field(block_key): """ Gets the explicit graded field to the given value for the given block. """ return block_structure.get_transformer_block_field(block_key, cls, cls.EXPLICIT_GRADED_FIELD_NAME) block_types_to_ignore = {"course", "chapter", "sequential"} for block_key in block_structure.topological_traversal(): if block_key.block_type in block_types_to_ignore: _set_field(block_key, None) else: explicit_field_on_block = get_field_on_block(block_structure.get_xblock(block_key), "graded") if explicit_field_on_block is not None: _set_field(block_key, explicit_field_on_block) else: values_from_parents = [ _get_field(parent) for parent in block_structure.get_parents(block_key) if parent.block_type not in block_types_to_ignore ] non_null_values_from_parents = [value for value in values_from_parents if not None] explicit_from_parents = functools_reduce(lambda x, y: x or y, non_null_values_from_parents, None) _set_field(block_key, explicit_from_parents)