Exemplo n.º 1
0
def user_newhouse():

    # 前端提交了一个表单给我们,我们可以直接解析表单form
    house_dict = request.form.to_dict()
    # 获取重复的设施
    facility_ids = request.form.getlist('facility')

    house = House()
    house.user_id = session['user_id']
    house.title = house_dict.get('title')
    house.price = house_dict.get('price')
    house.area_id = house_dict.get('area_id')
    house.address = house_dict.get('address')
    house.root_count = house_dict.get('root_count')
    house.acreage = house_dict.get('acreage')
    house.unit = house_dict.get('unit')
    house.capacity = house_dict.get('capacity')
    house.beds = house_dict.get('beds')
    house.deposit = house_dict.get('deposit')
    house.min_days = house_dict.get('min_days')
    house.max_days = house_dict.get('max_days')

    # 保存到数据库
    if facility_ids:
        # 所有设施的列表
        facilitys = Facility.query.filter(Facility.id.in_(facility_ids)).all()
        house.facilities = facilitys
        # house.facilities.append(1) 原先做法,一个一个加,现在直接加列表,一次加一个列表
    try:
        house.add_update()
        # 将房屋id,一并传过去使用
        return jsonify(code=status_code.OK, house_id=house.id)
    except:
        return jsonify(status_code.DATABASE_ERROR)
Exemplo n.º 2
0
def user_newhouse():

    house_dict = request.form.to_dict()
    facility_ids = request.form.getlist('facility')

    house = House()
    house.user_id = session['user_id']
    house.title = house_dict.get('title')
    house.price = house_dict.get('price')
    house.area_id = house_dict.get('area_id')
    house.address = house_dict.get('address')
    house.root_count = house_dict.get('root_count')
    house.acreage = house_dict.get('acreage')
    house.unit = house_dict.get('unit')
    house.capacity = house_dict.get('capacity')
    house.beds = house_dict.get('beds')
    house.deposit = house_dict.get('deposit')
    house.min_days = house_dict.get('min_days')
    house.max_days = house_dict.get('max_days')

    if facility_ids:
        facilitys = Facility.query.filter(Facility.id.in_(facility_ids)).all()
        house.facilities = facilitys
    try:
        house.add_update()
    except:
        return jsonify(status_code.DATABASE_ERROR)
    return jsonify(code=status_code.OK, house_id=house.id)