Пример #1
0
    def sget(pk):
        city = city_base.get(pk)

        district_query = thirdparty_svc.ers.TDistrictQuery()
        district_query.city_id = city['id']
        district_query.is_valid = True
        with thrift_client('ers') as ers:
            districts = ers.query_district(district_query)
            districts = any_to_raw(districts)

        zone_query = thirdparty_svc.ers.TZoneQuery()
        zone_query.city_id = city['id']
        zone_query.is_valid = True
        with thrift_client('ers') as ers:
            zones = ers.query_zone(zone_query)
            zones = any_to_raw(zones)

        [_district.__setitem__('_zones', []) for _district in districts]
        districts_map = {district['id']: district for district in districts}
        for zone in zones:
            district = districts_map.get(zone['district_id'], None)
            if district:
                district['_zones'].append(zone)
        city['_districts'] = districts
        return city
Пример #2
0
    def sget(pk):
        city = city_base.get(pk)

        district_query = thirdparty_svc.ers.TDistrictQuery()
        district_query.city_id = city['id']
        district_query.is_valid = True
        with thrift_client('ers') as ers:
            districts = ers.query_district(district_query)
            districts = any_to_raw(districts)

        zone_query = thirdparty_svc.ers.TZoneQuery()
        zone_query.city_id = city['id']
        zone_query.is_valid = True
        with thrift_client('ers') as ers:
            zones = ers.query_zone(zone_query)
            zones = any_to_raw(zones)

        [_district.__setitem__('_zones', []) for _district in districts]
        districts_map = {district['id']: district for district in districts}
        for zone in zones:
            district = districts_map.get(zone['district_id'], None)
            if district:
                district['_zones'].append(zone)
        city['_districts'] = districts
        return city
Пример #3
0
def get_struct(user_id):
    with thrift_client('ers') as ers:
        result = ers.get_direct_struct(user_id)
        result = getresult_to_raw(result)

        region_group_query = thirdparty_svc.ers.TRegionGroupQuery()
        region_group_query.city_ids = result.city_ids
        region_group_query.show_all = True

        region_groups_of_city = ers.query_region_group(region_group_query)
        region_groups_of_city = any_to_raw(region_groups_of_city)

        region_group_ids = result.region_group_ids
        region_group_ids.extend([obj['id'] for obj in region_groups_of_city])
        region_groups = ers.mget_region_group(region_group_ids).values()
        for region_group in region_groups:
            regions = ers.get_regions_by_region_group_ids([region_group.id])
            setattr(region_group,'_regions',regions)
        regions = ers.mget_region(result.region_ids).values()
        for region in regions:
            region_group_of_alone_region = ers.get_region_group_by_region(region.id)
            for region_group in region_groups:
                if region_group_of_alone_region.id == region_group.id:
                    region_group._regions.append(region)
            else:
                setattr(region_group_of_alone_region,'_regions',[region])
                region_groups.append(region_group_of_alone_region)
        region_group_group_by_city_id = defaultdict(list)
        for region_group in region_groups:
            region_group_group_by_city_id[region_group.city_id].append(region_group)
        city_ids = list(set(result.city_ids+region_group_group_by_city_id.keys()))
        cities = city_base.get(city_ids)
        for city in cities:
            setattr(city,'_region_groups',region_group_group_by_city_id.get(city.id,[]))
        cities = getresult_to_raw(cities)
        result = cities
        return result
Пример #4
0
def get_struct(user_id):
    with thrift_client("ers") as ers:
        result = ers.get_direct_struct(user_id)
        result = getresult_to_raw(result)

        region_group_query = thirdparty_svc.ers.TRegionGroupQuery()
        region_group_query.city_ids = result.city_ids
        region_group_query.show_all = True

        region_groups_of_city = ers.query_region_group(region_group_query)
        region_groups_of_city = any_to_raw(region_groups_of_city)

        region_group_ids = result.region_group_ids
        region_group_ids.extend([obj["id"] for obj in region_groups_of_city])
        region_groups = ers.mget_region_group(region_group_ids).values()
        for region_group in region_groups:
            regions = ers.get_regions_by_region_group_ids([region_group.id])
            setattr(region_group, "_regions", regions)
        regions = ers.mget_region(result.region_ids).values()
        for region in regions:
            region_group_of_alone_region = ers.get_region_group_by_region(region.id)
            for region_group in region_groups:
                if region_group_of_alone_region.id == region_group.id:
                    region_group._regions.append(region)
            else:
                setattr(region_group_of_alone_region, "_regions", [region])
                region_groups.append(region_group_of_alone_region)
        region_group_group_by_city_id = defaultdict(list)
        for region_group in region_groups:
            region_group_group_by_city_id[region_group.city_id].append(region_group)
        city_ids = list(set(result.city_ids + region_group_group_by_city_id.keys()))
        cities = city_base.get(city_ids)
        for city in cities:
            setattr(city, "_region_groups", region_group_group_by_city_id.get(city.id, []))
        cities = getresult_to_raw(cities)
        result = cities
        return result
Пример #5
0
def get(pk):
    pk = int(pk)
    result = city_base.get(pk)
    return result
Пример #6
0
def _check_city_exists(city_id):
    city = city_service.get(city_id)
    return True if city else False
Пример #7
0
def _check_city_exists(city_id):
    city = city_service.get(city_id)
    return True if city else False
Пример #8
0
def get(pk):
    pk = int(pk)
    result = city_base.get(pk)
    return result