def structure_from_mongo(structure, course_context=None):
 with TIMER.timer('structure_from_mongo', course_context) as tagger:
  tagger.measure('blocks', len(structure['blocks']))
  check('seq[2]', structure['root'])
  check('list(dict)', structure['blocks'])
  for block in structure['blocks']:
   if ('children' in block['fields']):
    check('list(list[2])', block['fields']['children'])
  structure['root'] = BlockKey(*structure['root'])
  new_blocks = {}
  for block in structure['blocks']:
   if ('children' in block['fields']):
    block['fields']['children'] = [BlockKey(*child) for child in block['fields']['children']]
   new_blocks[BlockKey(block['block_type'], block.pop('block_id'))] = BlockData(**block)
  structure['blocks'] = new_blocks
  return structure

def structure_from_mongo ( structure , course_context = None ) : with TIMER . timer ( 'structure_from_mongo' , course_context ) as tagger : tagger . measure ( 'blocks' , len ( structure [ 'blocks' ] ) ) check ( 'seq[2]' , structure [ 'root' ] ) check ( 'list(dict)' , structure [ 'blocks' ] ) for block in structure [ 'blocks' ] : if ( 'children' in block [ 'fields' ] ) : check ( 'list(list[2])' , block [ 'fields' ] [ 'children' ] ) structure [ 'root' ] = BlockKey ( * structure [ 'root' ] ) new_blocks = { } for block in structure [ 'blocks' ] : if ( 'children' in block [ 'fields' ] ) : block [ 'fields' ] [ 'children' ] = [ BlockKey ( * child ) for child in block [ 'fields' ] [ 'children' ] ] new_blocks [ BlockKey ( block [ 'block_type' ] , block . pop ( 'block_id' ) ) ] = BlockData ( ** block ) structure [ 'blocks' ] = new_blocks return structure
converts the blocks key from a list [block_data] to a map {blockkey: block_data} .