def grading_context(course_structure):
 all_graded_blocks = []
 all_graded_subsections_by_type = OrderedDict()
 for chapter_key in course_structure.get_children(course_structure.root_block_usage_key):
  for subsection_key in course_structure.get_children(chapter_key):
   subsection = course_structure[subsection_key]
   scored_descendants_of_subsection = []
   if subsection.graded:
    for descendant_key in course_structure.post_order_traversal(filter_func=possibly_scored, start_node=subsection_key):
     scored_descendants_of_subsection.append(course_structure[descendant_key])
    subsection_info = {'subsection_block': subsection, 'scored_descendants': [child for child in scored_descendants_of_subsection if getattr(child, 'has_score', None)]}
    subsection_format = getattr(subsection, 'format', '')
    if (subsection_format not in all_graded_subsections_by_type):
     all_graded_subsections_by_type[subsection_format] = []
    all_graded_subsections_by_type[subsection_format].append(subsection_info)
    all_graded_blocks.extend(scored_descendants_of_subsection)
 return {'all_graded_subsections_by_type': all_graded_subsections_by_type, 'all_graded_blocks': all_graded_blocks}

def grading_context ( course_structure ) : all_graded_blocks = [ ] all_graded_subsections_by_type = OrderedDict ( ) for chapter_key in course_structure . get_children ( course_structure . root_block_usage_key ) : for subsection_key in course_structure . get_children ( chapter_key ) : subsection = course_structure [ subsection_key ] scored_descendants_of_subsection = [ ] if subsection . graded : for descendant_key in course_structure . post_order_traversal ( filter_func = possibly_scored , start_node = subsection_key ) : scored_descendants_of_subsection . append ( course_structure [ descendant_key ] ) subsection_info = { 'subsection_block' : subsection , 'scored_descendants' : [ child for child in scored_descendants_of_subsection if getattr ( child , 'has_score' , None ) ] } subsection_format = getattr ( subsection , 'format' , '' ) if ( subsection_format not in all_graded_subsections_by_type ) : all_graded_subsections_by_type [ subsection_format ] = [ ] all_graded_subsections_by_type [ subsection_format ] . append ( subsection_info ) all_graded_blocks . extend ( scored_descendants_of_subsection ) return { 'all_graded_subsections_by_type' : all_graded_subsections_by_type , 'all_graded_blocks' : all_graded_blocks }
this returns a dictionary with keys necessary for quickly grading a student .