import itertools


def combined_levels(dimensions, default_only=False):
    """Create a cartesian product of levels from all `dimensions`. For
    example, if dimensions are _date_, _product_ then result will be:
    levels of _date_ X levels of _product_. Each element of the returned list
    is a list of tuples (`dimension`, `level`)
    """
    groups = []
    for dim in dimensions:
        if default_only:
            levels = dim.hierarchy().levels
        else:
            levels = dim.levels

        group = [(str(dim), str(level)) for level in levels]
        groups.append(group)

    return tuple(itertools.product(*groups))