(domain, filters)
return level_1s, l2s_by_l1, l3s_by_l2, l4s_by_l3
Returns dictionaries of location levels, keyed on the ID of their
    parent level. (e.g. {'MA': ['Boston', 'Cambridge']}) The user's
    filters are applied.
Returns dictionaries of location levels, keyed on the ID of their
    parent level. (e.g. {'MA': ['Boston', 'Cambridge']}) The user's
    filters are applied.
Returns dictionaries of location levels keyed on the ID of their parent level . ( e . g . { MA : [ Boston Cambridge ] } ) The user s filters are applied .
def get_sorted_levels(domain, filters) -> Tuple[list, dict, dict, dict]:
    """
    Returns dictionaries of location levels, keyed on the ID of their
    parent level. (e.g. {'MA': ['Boston', 'Cambridge']}) The user's
    filters are applied.
    """
    l3s_by_l2 = {}
    l4s_by_l3 = {}
    data_types_by_tag = get_data_types_by_tag(domain)
    level_1s = get_fixture_dicts(
        domain,
        data_types_by_tag["level_1_eco"]._id,
        filter_in={
            'id': [filters['level_1']] if filters['level_1'] else None
        },
        filter_out={'other': '1'},
    )
    l2s_by_l1 = get_fixture_dicts_by_key(
        domain,
        data_type_id=data_types_by_tag["level_2_eco"]._id,
        key='level_1_eco',
        filter_in={
            'level_1_eco': [l['id'] for l in level_1s],
            'id': [filters['level_2']] if filters['level_2'] else None
        },
        filter_out={'other': '1'},
    )
    l3_data_items = get_fixture_items_for_data_type(
        domain, data_type_id=data_types_by_tag["level_3_eco"]._id,
    )
    country_has_level_3 = len(l3_data_items) > 1
    if country_has_level_3:
        l3s_by_l2 = get_fixture_dicts_by_key(
            domain,
            data_type_id=data_types_by_tag["level_3_eco"]._id,
            key='level_2_eco',
            filter_in={
                'level_2_eco': [l2['id'] for l2s in l2s_by_l1.values() for l2 in l2s],
                'id': [filters['level_3']] if filters['level_3'] else None
            },
            filter_out={'other': '1'},
        )
        l4_data_items = get_fixture_items_for_data_type(
            domain, data_type_id=data_types_by_tag["level_4_eco"]._id,
        )
        country_has_level_4 = len(l4_data_items) > 1
        if country_has_level_4:
            l4s_by_l3 = get_fixture_dicts_by_key(
                domain,
                data_type_id=data_types_by_tag["level_4_eco"]._id,
                key='level_3_eco',
                filter_in={
                    'level_3_eco': [l3['id'] for l3s in l3s_by_l2.values() for l3 in l3s],
                    'id': [filters['level_4']] if filters['level_4'] else None
                },
                filter_out={'other': '1'},
            )
    return level_1s, l2s_by_l1, l3s_by_l2, l4s_by_l3
def get_sorted_levels ( domain , filters ) -> Tuple [ list , dict , dict , dict ] : l3s_by_l2 = { } l4s_by_l3 = { } data_types_by_tag = get_data_types_by_tag ( domain ) level_1s = get_fixture_dicts ( domain , data_types_by_tag [ "level_1_eco" ] . _id , filter_in = { 'id' : [ filters [ 'level_1' ] ] if filters [ 'level_1' ] else None } , filter_out = { 'other' : '1' } , ) l2s_by_l1 = get_fixture_dicts_by_key ( domain , data_type_id = data_types_by_tag [ "level_2_eco" ] . _id , key = 'level_1_eco' , filter_in = { 'level_1_eco' : [ l [ 'id' ] for l in level_1s ] , 'id' : [ filters [ 'level_2' ] ] if filters [ 'level_2' ] else None } , filter_out = { 'other' : '1' } , ) l3_data_items = get_fixture_items_for_data_type ( domain , data_type_id = data_types_by_tag [ "level_3_eco" ] . _id , ) country_has_level_3 = len ( l3_data_items ) > 1 if country_has_level_3 : l3s_by_l2 = get_fixture_dicts_by_key ( domain , data_type_id = data_types_by_tag [ "level_3_eco" ] . _id , key = 'level_2_eco' , filter_in = { 'level_2_eco' : [ l2 [ 'id' ] for l2s in l2s_by_l1 . values ( ) for l2 in l2s ] , 'id' : [ filters [ 'level_3' ] ] if filters [ 'level_3' ] else None } , filter_out = { 'other' : '1' } , ) l4_data_items = get_fixture_items_for_data_type ( domain , data_type_id = data_types_by_tag [ "level_4_eco" ] . _id , ) country_has_level_4 = len ( l4_data_items ) > 1 if country_has_level_4 : l4s_by_l3 = get_fixture_dicts_by_key ( domain , data_type_id = data_types_by_tag [ "level_4_eco" ] . _id , key = 'level_3_eco' , filter_in = { 'level_3_eco' : [ l3 [ 'id' ] for l3s in l3s_by_l2 . values ( ) for l3 in l3s ] , 'id' : [ filters [ 'level_4' ] ] if filters [ 'level_4' ] else None } , filter_out = { 'other' : '1' } , ) return level_1s , l2s_by_l1 , l3s_by_l2 , l4s_by_l3