@classmethod
def _flatten_mapping(cls, mapping, prefix=''):
    """Flatten a mapping for rendering templates."""
    new_mapping = {}
    for key, value in list(mapping.items()):
        if isinstance(value, dict):
            value = cls._flatten_mapping(value, prefix + '_' + key if
                prefix else key)
            new_mapping.update(value)
        else:
            new_mapping[prefix + '_' + key if prefix else key] = value
    return new_mapping
