def structure_to_mongo(structure, course_context=None):
 with TIMER.timer('structure_to_mongo', course_context) as tagger:
  tagger.measure('blocks', len(structure['blocks']))
  check('BlockKey', structure['root'])
  check('dict(BlockKey: BlockData)', structure['blocks'])
  for block in structure['blocks'].itervalues():
   if ('children' in block.fields):
    check('list(BlockKey)', block.fields['children'])
  new_structure = dict(structure)
  new_structure['blocks'] = []
  for (block_key, block) in structure['blocks'].iteritems():
   new_block = dict(block.to_storable())
   new_block.setdefault('block_type', block_key.type)
   new_block['block_id'] = block_key.id
   new_structure['blocks'].append(new_block)
  return new_structure

def structure_to_mongo ( structure , course_context = None ) : with TIMER . timer ( 'structure_to_mongo' , course_context ) as tagger : tagger . measure ( 'blocks' , len ( structure [ 'blocks' ] ) ) check ( 'BlockKey' , structure [ 'root' ] ) check ( 'dict(BlockKey: BlockData)' , structure [ 'blocks' ] ) for block in structure [ 'blocks' ] . itervalues ( ) : if ( 'children' in block . fields ) : check ( 'list(BlockKey)' , block . fields [ 'children' ] ) new_structure = dict ( structure ) new_structure [ 'blocks' ] = [ ] for ( block_key , block ) in structure [ 'blocks' ] . iteritems ( ) : new_block = dict ( block . to_storable ( ) ) new_block . setdefault ( 'block_type' , block_key . type ) new_block [ 'block_id' ] = block_key . id new_structure [ 'blocks' ] . append ( new_block ) return new_structure
converts the blocks key from a map {blockkey: block_data} to a list [block_data] .