Ejemplo n.º 1
0
def set_is_valid():
    args_spec = {"zone_id": Arg(int), "zone_ids": Arg(default=[]), "is_valid": Arg(bool)}
    args = args_parser.parse(args_spec)
    zone_id = args["zone_id"]
    zone_ids = args["zone_ids"]
    if zone_id:
        zone_ids.append(zone_id)
    zone_base.set_is_valid(zone_ids, args["is_valid"])
    return ""
Ejemplo n.º 2
0
def set_is_valid():
    args_spec = {
        'zone_id': Arg(int),
        'zone_ids': Arg(default=[]),
        'is_valid': Arg(bool),
    }
    args = args_parser.parse(args_spec)
    zone_id = args['zone_id']
    zone_ids = args['zone_ids']
    if zone_id:
        zone_ids.append(zone_id)
    zone_base.set_is_valid(zone_ids, args['is_valid'])
    return ''
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)