示例#1
0
def change_director_region(user_id, old_region, new_region):
    city_diff = _diff(old_region.city_ids, new_region.city_ids)
    region_group_diff = _diff(old_region.region_group_ids, new_region.region_group_ids)
    region_diff = _diff(old_region.region_ids, new_region.region_ids)

    query_dict = {}
    if city_diff:
        query_dict["city_ids"] = city_diff
    if region_group_diff:
        query_dict["region_group_ids"] = region_group_diff
    if region_diff:
        query_dict["region_ids"] = region_diff

    if not query_dict:
        return

    dir_records = rst_dir_base.query_restaurant_director(director_ids=[user_id], offset=0, limit=1000)
    dir_rst_ids = [d.restaurant_id for d in dir_records]
    query_dict["restaurant_ids"] = dir_rst_ids
    query_dict["offset"] = 0
    query_dict["limit"] = 1000

    restaurants = rst_dir_base.search_restaurants(**query_dict)
    rst_ids = [r["id"] for r in restaurants[0]]
    rst_dir_base.rm_restaurant_director(user_id, rst_ids)
示例#2
0
def change_director_region(user_id, old_region, new_region):
    city_diff = _diff(old_region.city_ids, new_region.city_ids)
    region_group_diff = _diff(old_region.region_group_ids,
                              new_region.region_group_ids)
    region_diff = _diff(old_region.region_ids, new_region.region_ids)

    query_dict = {}
    if city_diff:
        query_dict['city_ids'] = city_diff
    if region_group_diff:
        query_dict['region_group_ids'] = region_group_diff
    if region_diff:
        query_dict['region_ids'] = region_diff

    if not query_dict:
        return

    dir_records = rst_dir_base.query_restaurant_director(
        director_ids=[user_id], offset=0, limit=1000)
    dir_rst_ids = [d.restaurant_id for d in dir_records]
    query_dict['restaurant_ids'] = dir_rst_ids
    query_dict['offset'] = 0
    query_dict['limit'] = 1000

    restaurants = rst_dir_base.search_restaurants(**query_dict)
    rst_ids = [r['id'] for r in restaurants[0]]
    rst_dir_base.rm_restaurant_director(user_id, rst_ids)
示例#3
0
def set_bd_restaurant_director(user_id, rst_ids, notice_enabled=True, in_charge=True):
    old_rst_dir = rst_dir_base.query_restaurant_director(director_ids=[user_id], offset=0, limit=1000)
    new_rst_dir = rst_dir_base.query_restaurant_director(restaurant_ids=rst_ids, offset=0, limit=1000)

    old_rst_ids = [rst_dir.restaurant_id for rst_dir in old_rst_dir]
    new_rst_ids = [rst_dir.restaurant_id for rst_dir in new_rst_dir]
    rm_rst_ids = _diff(old_rst_ids, new_rst_ids)
    add_rst_ids = _diff(new_rst_ids, old_rst_ids)

    rst_dir_base.rm_restaurant_director(user_id, rm_rst_ids)
    rst_dir_base.set_restaurant_director(user_id, add_rst_ids, notice_enabled, in_charge)
示例#4
0
def clean_rst_director():
    dir_rst_map = get_director_rst_map()

    for user_id, rst_ids in dir_rst_map.items():
        if user_base.is_superadmin(user_id):
            continue

        rst_to_clean = get_rst_not_in_charge(user_id, rst_ids)

        if rst_to_clean:
            log.info('clean {} \'s restaurant: [{}]'.format(
                user_id, rst_to_clean.__repr__()))
            rst_dir_base.rm_restaurant_director(user_id, rst_to_clean)
示例#5
0
def clean_rst_director():
    dir_rst_map = get_director_rst_map()

    for user_id, rst_ids in dir_rst_map.items():
        if user_base.is_superadmin(user_id):
            continue

        rst_to_clean = get_rst_not_in_charge(user_id, rst_ids)

        if rst_to_clean:
            log.info('clean {} \'s restaurant: [{}]'.format(
                user_id, rst_to_clean.__repr__()))
            rst_dir_base.rm_restaurant_director(user_id, rst_to_clean)
示例#6
0
def set_bd_restaurant_director(user_id,
                               rst_ids,
                               notice_enabled=True,
                               in_charge=True):
    old_rst_dir = rst_dir_base\
        .query_restaurant_director(director_ids=[user_id,], offset=0, limit=1000)
    new_rst_dir = rst_dir_base\
        .query_restaurant_director(restaurant_ids=rst_ids, offset=0, limit=1000)

    old_rst_ids = [rst_dir.restaurant_id for rst_dir in old_rst_dir]
    new_rst_ids = [rst_dir.restaurant_id for rst_dir in new_rst_dir]
    rm_rst_ids = _diff(old_rst_ids, new_rst_ids)
    add_rst_ids = _diff(new_rst_ids, old_rst_ids)

    rst_dir_base.rm_restaurant_director(user_id, rm_rst_ids)
    rst_dir_base.set_restaurant_director(user_id, add_rst_ids, notice_enabled,
                                         in_charge)