Esempio n. 1
0
def my_newhouse():
    data = request.form.to_dict()
    facility_ids = request.form.getlist('facility')

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

    facility_list = Facility.query.filter(Facility.id.in_(facility_ids)).all()
    house.facilities = facility_list
    try:
        house.add_update()
    except:
        db.session.rollback()
    return jsonify(code=200, house_id=house.id)
Esempio n. 2
0
def newhouse_save():
    # 接收数据
    params = request.form.to_dict()
    facility_ids = request.form.getlist('facility')
    # 验证数据的有效性

    # 创建对象并保存
    # 1.给对象的字段分别赋值
    house = House()
    house.user_id = session['user_id']
    house.area_id = params.get('area_id')
    house.title = params.get('title')
    house.price = params.get('price')
    house.address = params.get('address')
    house.room_count = params.get('room_count')
    house.acreage = params.get('acreage')
    house.beds = params.get('beds')
    house.unit = params.get('unit')
    house.capacity = params.get('capacity')
    house.deposit = params.get('deposit')
    house.min_days = params.get('min_days')
    house.max_days = params.get('max_days')
    # 根据设施的编号查询设施对象
    if facility_ids:
        facility_list = Facility.query.filter(
            Facility.id.in_(facility_ids)).all()
        house.facilities = facility_list
    house.add_update()
    # 返回结果
    return jsonify(code='200', house_id=house.id)
Esempio n. 3
0
def new_house():
    #接收用户信息
    params = request.form.to_dict()
    facility_ids = request.form.getlist('facility')

    #创建房源信息
    house = House()
    house.user_id = session['user_id']
    house.area_id = params.get('area_id')
    house.title = params.get('title')
    house.price = params.get('price')
    house.address = params.get('address')
    house.room_count = params.get('room_count')
    house.acreage = params.get('acreage')
    house.beds = params.get('beds')
    house.unit = params.get('unit')
    house.capacity = params.get('capacity')
    house.deposit = params.get('deposit')
    house.min_days = params.get('min_days')
    house.max_days = params.get('max_days')
    #通过设施编号查询设施对象
    if facility_ids:
        facility_list = Facility.query.filter(
            Facility.id.in_(facility_ids)).all()
        house.facilities = facility_list
    house.add_update()
    return jsonify(code=200, house_id=house.id)
Esempio n. 4
0
def house_info():
    title = request.form.get('title')
    price = request.form.get('price')
    area_id = request.form.get('area_id')
    address = request.form.get('address')
    room_count = request.form.get('room_count')
    acreage = request.form.get('acreage')
    unit = request.form.get('unit')
    capacity = request.form.get('capacity')
    beds = request.form.get('beds')
    deposit = request.form.get('deposit')
    min_days = request.form.get('min_days')
    max_days = request.form.get('max_days')
    facility = request.form.getlist('facility')
    house = House()
    house.user_id = session.get('user_id')
    house.title = title
    house.price = price
    house.area_id = area_id
    house.address = address
    house.room_count = room_count
    house.acreage = acreage
    house.unit = unit
    house.capacity = capacity
    house.beds = beds
    house.deposit = deposit
    house.min_days = min_days
    house.max_days = max_days
    f = []
    for i in facility:
        fac = Facility.query.filter_by(id=i).first()
        f.append(fac)
    house.facilities = f
    house.add_update()
    return jsonify({'code':200,'msg':'请求成功','data':house.id})
Esempio n. 5
0
def new_house():
    if request.method == 'GET':
        return render_template('newhouse.html')

    if request.method == 'POST':
        # 接收用户信息
        params = request.form.to_dict()
        facility_ids = request.form.getlist('facility')

        # 创建用户信息
        house = House()
        house.user_id = session['user_id']
        house.area_id = params.get('area_id')
        house.title = params.get('title')
        house.price = params.get('price')
        house.address = params.get('address')
        house.room_count = params.get('room_count')
        house.acreage = params.get('acreage')
        house.beds = params.get('beds')
        house.unit = params.get('unit')
        house.capacity = params.get('capacity')
        house.deposit = params.get('deposit')
        house.min_days = params.get('min_days')
        house.max_days = params.get('max_days')
        # 根据设施的编号查询设施对象
        if facility_ids:
            facility_list = Facility.query.filter(
                Facility.id.in_(facility_ids)).all()
            house.facilities = facility_list
        house.add_update()
        # 返回结果
        return jsonify(code='200', house_id=house.id)
Esempio n. 6
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)
Esempio n. 7
0
def add_newhouse():
    if request.method == 'POST':
        house_title = request.form.get('title')
        house_price = int(request.form.get('price'))
        area_id = int(request.form.get('area_id'))
        house_address = request.form.get('address')
        house_room_count = int(request.form.get('room_count'))
        house_acreage = int(request.form.get('acreage'))
        house_unit = request.form.get('unit')
        house_capacity = request.form.get('capacity')
        house_beds = request.form.get('beds')
        house_deposit = request.form.get('deposit')
        house_min_days = int(request.form.get('min_days'))
        house_max_days = int(request.form.get('max_days'))

        user_id = session.get('user_id')

        if not (house_title or house_price or area_id or house_address
                or house_room_count or house_acreage or house_unit
                or house_max_days or house_capacity or house_beds
                or house_deposit or house_min_days):
            return jsonify({'code': 1014, 'msg': '请将信息填写完整'})
        if house_price <= 0:
            return jsonify({'code': 1015, 'msg': '请输入正确的价格'})
        if house_min_days <= 0 or house_max_days < 0:
            return jsonify({'code': 1017, 'msg': '请输入正确的入住天数'})
        if house_max_days != 0 and house_max_days < house_min_days:
            return jsonify({'code': 1017, 'msg': '请输入正确的入住天数'})

        house = House()
        house.user_id = user_id
        house.title = house_title
        house.price = house_price
        house.area_id = area_id
        house.address = house_address
        house.room_count = house_room_count
        house.acreage = house_acreage
        house.unit = house_unit
        house.capacity = house_capacity
        house.beds = house_beds
        house.deposit = house_deposit
        house.min_days = house_min_days
        house.max_days = house_max_days

        # 保存房屋设施到数据库
        house_facs_min = []
        house_facs = request.form.getlist('facility')
        for house_fac in house_facs:
            house_fac = int(house_fac)
            fac = Facility.query.get(house_fac)
            house_facs_min.append(fac)
        house.facilities = house_facs_min

        house.add_update()
        session['house_id'] = house.id
        house_id = house.id

    return jsonify({'code': 200, 'msg': '请输入正确的床位', 'house_id': house_id})
Esempio n. 8
0
def publish_house():
    title = request.form.get('title')
    price = request.form.get('price')
    area_id = request.form.get('area_id')
    address = request.form.get('address')
    room_count = request.form.get('room_count')
    acreage = request.form.get('acreage')
    unit = request.form.get('unit')
    capacity = request.form.get('capacity')
    beds = request.form.get('beds')
    deposit = request.form.get('deposit')
    min_days = request.form.get('min_days')
    max_days = request.form.get('max_days')
    check_val = request.form.get('check_val')

    if not all([
            title, price, area_id, address, room_count, acreage, unit,
            capacity, beds, deposit, min_days, max_days, check_val
    ]):
        return jsonify(status_code.HOUSE_PARAMS_NOT_COMPLETE)

    house = House()
    house.user_id = session.get('user_id')
    house.title = title
    house.price = price
    house.area_id = area_id
    house.address = address
    house.room_count = room_count
    house.acreage = acreage
    house.unit = unit
    house.capacity = capacity
    house.beds = beds
    house.deposit = deposit
    house.min_days = min_days
    house.max_days = max_days
    fid_list = check_val[:-1]
    try:
        f_list = Facility.query.filter(Facility.id.in_(fid_list)).all()
        house.facilities = f_list

        house.add_update()
        res = status_code.SUCCESS
        res['data'] = house.to_dict()
        return jsonify(res)
    except BaseException as e:
        print(e)
        db.session.rollback()
        return jsonify(status_code.DATABASE_ERROR)
Esempio n. 9
0
def newihouse():
    facility_ids = request.form.getlist('facility')
    house = House()
    house.user_id = session['user_id']
    house.area_id = request.form.get('area_id')
    house.title = request.form.get('title')
    house.price = request.form.get('price')
    house.address = request.form.get('address')
    house.room_count = request.form.get('room_count')
    house.acreage = request.form.get('acreage')
    house.beds = request.form.get('beds')
    house.unit = request.form.get('unit')
    house.capacity = request.form.get('capacity')
    house.deposit = request.form.get('deposit')
    house.min_days = request.form.get('min_days')
    house.max_days = request.form.get('max_days')
    if facility_ids:
        facility_list = Facility.query.filter(Facility.id.in_(facility_ids)).all()
        house.facilities = facility_list
    house.add_update()
    return jsonify({'code': 200, 'msg': '请求成功', 'house_id': house.id})
Esempio n. 10
0
def new_house():
    if request.method == 'GET':
        return render_template('newhouse.html')

    if request.method == 'POST':
        # 接收用户信息
        params = request.form.to_dict()
        facility_ids = request.form.getlist('facility')

        # 创建用户信息
        house = House()
        house.user_id = session['user_id']
        house.title = params.get('title')
        house.city = params.get('city')
        house.area = params.get('area')
        house.street = params.get('street')
        house.village = params.get('village')
        house.address = params.get('address')
        house.price = params.get('price')
        house.room_count = params.get('room_count')
        house.acreage = params.get('acreage')
        house.unit = params.get('unit')
        house.direction = params.get('direction')
        total_floor = params.get('total-floor')
        house.floor = params.get('floor') + '/' + total_floor
        house.desc = params.get('desc')
        house.have_cook_bath = True if params.get(
            'cook-bath-room') == 'single' else False

        # 根据设施的编号查询设施对象
        if facility_ids:
            facility_list = Facility.query.filter(
                Facility.id.in_(facility_ids)).all()
            house.facilities = facility_list
        house.add_update()
        # 返回结果
        return jsonify(code='200', house_id=house.id)
Esempio n. 11
0
def save_new_house():
    """
    前端发送过来的json数据
    {
        "title":"",
        "price":"",
        "area_id":"1",
        "address":"",
        "room_count":"",
        "acreage":"",
        "unit":"",
        "capacity":"",
        "beds":"",
        "deposit":"",
        "min_days":"",
        "max_days":"",
        "facility":["7","8"]
    }

    :return:
    """
    # 1.获取用户id
    user_id = g.user_id
    # 2. 获取数据
    json_dict = request.get_json()
    if not json_dict:
        return jsonify(errno=RET.PARAMERR, errmsg='请输入参数')
    # 3.参数校验
    title = json_dict.get('title')  # 房屋标题
    price = json_dict.get('price')  # 每晚价格
    address = json_dict.get('address')  # 所在城区
    area_id = json_dict.get('area_id')  # 详细地址
    room_count = json_dict.get('room_count')  # 出租房间数目
    acreage = json_dict.get('acreage')  # 房屋面积
    unit = json_dict.get('unit')  # 户型描述
    capacity = json_dict.get('capacity')  # 宜住人数
    beds = json_dict.get('beds')  # 卧床配置
    deposit = json_dict.get('deposit')  # 押金数额
    min_days = json_dict.get('min_days')  # 最少入住天数
    max_days = json_dict.get('max_days')  # 最多入住天数

    if not all([
            title, price, address, area_id, room_count, acreage, unit,
            capacity, beds, deposit, min_days, max_days
    ]):
        return jsonify(errno=RET.PARAMERR, errmsg='参数缺失')

    # 数字信息处理,保证信息小数点后两位不丢失
    try:
        price = int(float(price) * 100)
        deposit = int(float(deposit) * 100)
    except Exception as e:
        logging.error(e)
        return jsonify(errno=RET.PARAMERR, errmsg='参数错误')

    # 4. 设置数据到模型
    house = House()
    house.user_id = user_id
    house.area_id = area_id
    house.title = title
    house.price = price
    house.address = address
    house.room_count = room_count
    house.acreage = acreage
    house.unit = unit
    house.capacity = capacity
    house.beds = beds
    house.deposit = deposit
    house.min_days = min_days
    house.max_days = max_days

    # 5. 设置设施信息
    facility = json_dict.get('facility')
    if facility:
        facilities = Facility.query.filter(Facility.id.in_(facility)).all()
        house.facilities = facilities
    # 6.向数据库提交信息
    try:
        db.session.add(house)
        db.session.commit()
    except Exception as e:
        logging.error(e)
        db.session.rollback()
        return jsonify(errno=RET.DBERR, errmsg='保存房屋信息失败')

    return jsonify(errno=RET.OK, errmsg='OK', data={'house_id': house.id})