'Internal recursive implementation of copy_from_template()
Returns the new set of BlockKeys that are the new descendants of the block with key \'block_key\''

def _copy_from_template(self, source_structures, source_keys, dest_structure, new_parent_block_key, user_id, head_validation):

    new_blocks = set()
    new_children = list()
    for usage_key in source_keys:
        src_course_key = usage_key.course_key
        hashable_source_id = src_course_key.for_version(None)
        block_key = BlockKey(usage_key.block_type, usage_key.block_id)
        source_structure = source_structures[src_course_key]
        if (block_key not in source_structure['blocks']):
            raise ItemNotFoundError(usage_key)
        source_block_info = source_structure['blocks'][block_key]
        unique_data = '{}:{}:{}'.format(unicode(hashable_source_id).encode('utf-8'), block_key.id, new_parent_block_key.id)
        new_block_id = hashlib.sha1(unique_data).hexdigest()[:20]
        new_block_key = BlockKey(block_key.type, new_block_id)
        new_block_info = copy.deepcopy(source_block_info)
        existing_block_info = dest_structure['blocks'].get(new_block_key, BlockData())
        new_block_info.defaults = new_block_info.fields
        if ((usage_key.block_type == 'problem') and ('markdown' in new_block_info.defaults)):
            del new_block_info.defaults['markdown']
        new_block_info.fields = existing_block_info.fields
        if ('children' in new_block_info.defaults):
            del new_block_info.defaults['children']
        new_block_info.edit_info = existing_block_info.edit_info
        new_block_info.edit_info.previous_version = new_block_info.edit_info.update_version
        new_block_info.edit_info.update_version = dest_structure['_id']
        new_block_info.edit_info.edited_by = user_id
        new_block_info.edit_info.edited_on = datetime.datetime.now(UTC)
        new_block_info.edit_info.original_usage = unicode(usage_key.replace(branch=None, version_guid=None))
        new_block_info.edit_info.original_usage_version = source_block_info.edit_info.update_version
        dest_structure['blocks'][new_block_key] = new_block_info
        children = source_block_info.fields.get('children')
        if children:
            children = [src_course_key.make_usage_key(child.type, child.id) for child in children]
            new_blocks |= self._copy_from_template(source_structures, children, dest_structure, new_block_key, user_id, head_validation)
        new_blocks.add(new_block_key)
        new_children.append(new_block_key)
    dest_structure['blocks'][new_parent_block_key].fields['children'] = new_children
    return new_blocks
