Пример #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)
Пример #2
0
def newhouses_post():
    params = request.form.to_dict()
    facility_ids = request.form.getlist('facility')
    # 用户id
    user_id = session['user_id']
    # 房间标题
    house_title = params.get('title')
    # 房间价格
    house_price = params.get('price')
    # 所在城区
    area_id = params.get('area_id')
    # 房间地址
    house_address = params.get('address')
    # 房间数量
    house_room_count = params.get('room_count')
    # 房屋面积
    house_acreage = params.get('acreage')
    # 户型描述
    house_unit = params.get('unit')
    # 适宜人数
    house_capacity = params.get('capacity')
    # 卧床配置
    house_beds = params.get('beds')
    # 押金数额
    house_deposit = params.get('deposit')
    # 最少入住天数
    house_min_days = params.get('min_days')
    # 最多入住天数
    house_max_days = params.get('max_days')
    # 配套设施
    facility = params.get('facility')

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

    if facility_ids:
        facility_list = Facility.query.filter(
            Facility.id.in_(facility_ids)).all()
        houses.facilities = facility_list

    try:
        houses.add_update()
    except Exception as e:
        db.session.rollback()
        return jsonify(status_code.DATABASE_ERROR)

    return jsonify({'code': '200', 'msg': houses.id})
Пример #3
0
def newhouse_post():
    house_dict = request.form.to_dict()
    facility_ids = request.form.getlist('facility')

    house = House()
    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.room_count = house_dict.get('room_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')
    house.user_id = session['user_id']
    if facility_ids:
        facilitys = Facility.query.filter(Facility.id.in_(facility_ids)).all()
        house.facilities = facilitys
    try:
        house.add_update()
        return jsonify(code=status_code.OK,house_id=house.id)
    except:
        return jsonify(status_code.DATABASE_ERROR)
Пример #4
0
def new_house_info():
    # 获取前端提交过来的参数
    params = request.form.to_dict()
    # 获取配置设备信息
    facility_ids = request.form.getlist('facility')
    # 创建House对象
    house = House()
    house.user_id = session['user_id']
    house.title = params.get('title')
    house.area_id = params.get('area_id')
    house.price = params.get('price')
    house.address = params.get('address')
    house.room_count = params.get('room_count')
    house.acreage = params.get('acreage')
    house.unit = params.get('unit')
    house.capacity = params.get('capacity')
    house.beds = params.get('beds')
    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
    try:
        house.add_update()
    except:
        db.session.rollback()
        return jsonify(status_code.DATABASE_ERROR)
    return jsonify(code=status_code.ok, house_id=house.id)
Пример #5
0
def user_new_house():
    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.house_id = 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=status_code.OK, house_id=house.id)
Пример #6
0
def newhouse_save():
    #接收数据
    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)
Пример #7
0
def publish_house():
    """
    发布新房源
    """
    data = request.form.to_dict()
    user_id = session['user_id']
    facility_ids = request.form.getlist('facility')

    house = House()
    house.user_id = 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

    house.add_update()

    return jsonify(code=status_code.OK, house_id=house.id)
Пример #8
0
def save_info():
    house_dict = request.form
    title = house_dict.get('title')
    price = house_dict.get('price')
    address= house_dict.get('address')
    room_count= house_dict.get('room_count')
    acreage= house_dict.get('acreage')
    unit = house_dict.get('unit')
    capacity= house_dict.get('capacity')
    beds= house_dict.get('beds')
    deposit= house_dict.get('deposit')
    min_days= house_dict.get('min_days')
    max_days= house_dict.get('max_days')
    area_id= house_dict.get('area_id')
    facilitys= house_dict.getlist('facility')
    user_id = session['user_id']

    house = House()
    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
    house.area_id = area_id
    house.user_id = user_id

    # try:
    #     house.add_update()
    #     for facility in facilitys:
    #         sql = 'insert into ihome_house_facility(house_id, facility_id) values(%s, %s)' % (house.id, facility)
    #         db.session.execute(sql)
    #         db.session.commit()
    #     return jsonify(SUCCESS)
    # except Exception as e:
    #     return jsonify(DATABASE_ERROR)
    if facilitys:
        facility = Facility.query.filter(Facility.id.in_(facilitys)).all()
        house.facilities = facility
    house.add_update()
    return jsonify(code=OK, house_id=house.id)
Пример #9
0
def user_newhouse():
    house_dict = request.form
    title = house_dict.get('title')
    price = house_dict.get('price')
    area_id = house_dict.get('area_id')
    address = house_dict.get('address')
    room_count = house_dict.get('room_count')
    acreage = house_dict.get('acreage')
    unit = house_dict.get('unit')
    capacity = house_dict.get('capacity')
    beds = house_dict.get('beds')
    deposit = house_dict.get('deposit')
    min_days = house_dict.get('min_days')
    max_days = house_dict.get('max_days')
    facility_ids = house_dict.getlist('facility')

    house = House()
    house.user_id = session['user_id']
    house.title = title
    house.area_id = area_id
    house.address = address
    house.price = price
    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

    if facility_ids:
        fas = Facility.query.filter(Facility.id.in_(facility_ids)).all()
        house.facilities = fas

    try:
        house.add_update()
        return jsonify(code=status_code.OK, house_id=house.id)
    except:
        return jsonify(status_code.DATABASE_ERROR)