@classmethod
def prep_filter_for_str(cls, start, items):
    """
        Routine used to convert wh and hv attributes to the WHERE
        and HAVING parts of the resulting SQL query. Function is only
        used internally by the __str__ conversion and therefore not 
        documented any further.
        """
    output = ''
    kw = start
    for k, v in items.items():
        if isinstance(k, tuple):
            l = len(k)
            kw += ' ('
            for i in range(l):
                output += cls.filter_to_str(kw, k[i], v[i])
                kw = 'OR'
            output += ')'
            kw = 'AND'
        elif isinstance(v, tuple):
            output += cls.filter_to_str(kw, k, v)
            kw = 'AND'
        elif isinstance(v, list):
            for v_in_l in v:
                output += cls.filter_to_str(kw, k, v_in_l)
                kw = 'AND'
    return output
