Esempio n. 1
0
def post_or_put(pk=None, dic=None):
    if pk is not None:
        pk = int(pk)
    # 处理新建与更新
    new_city = dic
    new_city['is_valid'] = True

    check_same(new_city)

    city_id = city_base.post_or_put(pk, new_city)
    new_city['id'] = city_id

    _districts = new_city.get('_districts', [])
    for _district in _districts:
        _district['is_valid'] = True
        _district['city_id'] = new_city['id']
        _district['id'] = district_base.post_or_put(_district['id'], _district)
        _zones = _district.get('_zones', [])
        for _zone in _zones:
            _zone['is_valid'] = True
            _zone['city_id'] = new_city['id']
            _zone['district_id'] = _district['id']
            _zone['id'] = zone_base.post_or_put(_zone['id'], _zone)
    # 处理删除
    if pk is not None:
        old_city = get(pk)
        old_districts = old_city.get('_districts', [])
        old_district_ids = set([district['id'] for district in old_districts])
        new_districts = new_city.get('_districts', [])
        new_district_ids = set([district['id'] for district in new_districts])
        delete_ids = list(old_district_ids - new_district_ids)

        district_base.set_is_valid(delete_ids, False)

        old_zones = reduce(
            operator.add,
            [_district.get('_zones', []) for _district in old_districts], [])
        old_zone_ids = set([zone['id'] for zone in old_zones])
        new_zones = reduce(
            operator.add,
            [_district.get('_zones', []) for _district in new_districts], [])
        new_zone_ids = set([zone['id'] for zone in new_zones])
        delete_ids = list(old_zone_ids - new_zone_ids)
        zone_base.set_is_valid(delete_ids, False)
Esempio n. 2
0
def post_or_put(pk=None, dic=None):
    if pk is not None:
        pk = int(pk)
    # 处理新建与更新
    new_city = dic
    new_city['is_valid'] = True

    check_same(new_city)

    city_id = city_base.post_or_put(pk, new_city)
    new_city['id'] = city_id

    _districts = new_city.get('_districts', [])
    for _district in _districts:
        _district['is_valid'] = True
        _district['city_id'] = new_city['id']
        _district['id'] = district_base.post_or_put(_district['id'], _district)
        _zones = _district.get('_zones', [])
        for _zone in _zones:
            _zone['is_valid'] = True
            _zone['city_id'] = new_city['id']
            _zone['district_id'] = _district['id']
            _zone['id'] = zone_base.post_or_put(_zone['id'], _zone)
    # 处理删除
    if pk is not None:
        old_city = get(pk)
        old_districts = old_city.get('_districts', [])
        old_district_ids = set([district['id'] for district in old_districts])
        new_districts = new_city.get('_districts', [])
        new_district_ids = set([district['id'] for district in new_districts])
        delete_ids = list(old_district_ids - new_district_ids)

        district_base.set_is_valid(delete_ids, False)

        old_zones = reduce(
            operator.add, [_district.get('_zones', []) for _district in old_districts], [])
        old_zone_ids = set([zone['id'] for zone in old_zones])
        new_zones = reduce(
            operator.add, [_district.get('_zones', []) for _district in new_districts], [])
        new_zone_ids = set([zone['id'] for zone in new_zones])
        delete_ids = list(old_zone_ids - new_zone_ids)
        zone_base.set_is_valid(delete_ids, False)
Esempio n. 3
0
def put(pk):
    pk = int(pk)
    city = args_to_tobj(thirdparty_svc.ers.TCity)
    city_base.post_or_put(pk, city)
    return ''
Esempio n. 4
0
def post():
    city = args_to_tobj(thirdparty_svc.ers.TCity)
    city_base.post_or_put(None, city)
    return ''
Esempio n. 5
0
def put(pk):
    pk = int(pk)
    city = args_to_tobj(thirdparty_svc.ers.TCity)
    city_base.post_or_put(pk, city)
    return ''
Esempio n. 6
0
def post():
    city = args_to_tobj(thirdparty_svc.ers.TCity)
    city_base.post_or_put(None, city)
    return ''