コード例 #1
0
ファイル: house_views.py プロジェクト: ThisNameError/i-home
def addhouse():
    # 接收数据
    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})
コード例 #2
0
def my_new_house():
    data = request.form
    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')
    # 获取设施列表, 使用getlist
    facilities = data.getlist('facility')
    for f_id in facilities:
        facility = Facility.query.get(f_id)
        # 添加房屋和设施的关联关系,多对多
        house.facilities.append(facility)
    house.add_update()
    house_id = house.id
    return jsonify({'house_id': house_id, 'code': 200})
コード例 #3
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)
コード例 #4
0
def my_newhouse():
    house = House()
    dict = request.form
    dict_house = dict.getlist('facility')

    #多对多给房间添加设施信息
    facilities = Facility.query.all()
    for i in dict_house:
        fac = Facility.query.filter(Facility.id == i).first()
        house.facilities.append(fac)

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

    return jsonify({'code': '200', 'msg': '添加成功', 'house_id': house.id})
コード例 #5
0
def my_new_house():
    # 创建房屋信息
    data = request.form
    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')

    # 获取设施信息,使用getlist
    facilities = data.getlist('facility')
    for f_id in facilities:
        facility = Facility.query.get(f_id)
        # 添加房屋和设施的关联关系,多对多
        house.facilities.append(facility)
    # commit,在数据库中创建house和设施的中间表数据
    house.add_update()
    return jsonify(code=status_code.OK, house_id=house.id)
コード例 #6
0
ファイル: house_views.py プロジェクト: NotBeBarnon/iHome
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})
コード例 #7
0
def newhouse():
    if request.method == 'GET':
        return render_template('newhouse.html')
    if request.method == 'POST':
        user = current_user
        user_id = user.id
        area_id = int(request.form.get('area_id'))
        title = request.form.get('title')
        price = int(request.form.get('price'))
        address = request.form.get('address')
        room_count = int(request.form.get('room_count'))
        acreage = int(request.form.get('acreage'))
        unit = request.form.get('unit')
        capacity = int(request.form.get('capacity'))
        beds = request.form.get('beds')
        deposit = int(request.form.get('deposit'))
        min_days = int(request.form.get('min_days'))
        max_days = int(request.form.get('max_days'))
        facilities = request.form.getlist('facility')
        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
        for facility in facilities:
            h_facility = Facility.query.filter_by(id=int(facility)).first()
            house.facilities.append(h_facility)
        house.add_update()
        house_id = house.id
        return jsonify({"code": OK, "house_id": house_id})
    if request.method == 'PATCH':
        house_image = request.files.get('house_image')
        house_id = int(request.form.get('house_id'))
        if is_graph(house_image.filename):
            file_path = os.path.join(UPLOAD_DIR, house_image.filename)
            house_image.save(file_path)
            # 保存图片路径到数据库
            house = House.query.get(house_id)
            if house.index_image_url == 'upload\haveno.jpg':
                house.index_image_url = os.path.join('upload', house_image.filename)
                house.add_update()
            else:
                houseimage = HouseImage()
                houseimage.house_id = house_id
                houseimage.url = os.path.join('upload', house_image.filename)
                houseimage.add_update()
            return jsonify({"code": OK, "house_image": os.path.join('upload', house_image.filename)})
        else:
            return jsonify({"code": NO})
コード例 #8
0
ファイル: houseViews.py プロジェクト: NKAtctor/ihome
def public_house():

    if request.method == 'POST':
        # 校验字段
        results = public_house_check(request.form)

        if results == 'True':
            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')
            facilitys = request.form.getlist('facility')

            user_id = session.get('user_id')

            house = House()
            house.user_id = user_id
            house.title = title
            house.area_id = area_id
            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
            # 存储设施第三张表

            # 获取到设施对象列表
            facility = house.facilities

            # 向第三张表中添加数据
            for a_id in facilitys:
                fac = Facility.query.filter(Facility.id == int(a_id)).first()
                facility.append(fac)

            house.save()

            session['house_id'] = house.id

            return jsonify(REQUEST_SUCCESS)
        else:
            REQUEST_FAIL['results'] = results
            return jsonify(REQUEST_FAIL)
コード例 #9
0
ファイル: house_views.py プロジェクト: 321203500/aijia
def newhouse_info():
    # 获取表单信息
    # 标题
    title = request.form.get('title')
    # 单价
    price = request.form.get('price')
    # 地址
    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')
    # 房屋设施
    facilities = request.form.getlist('facility')
    # 区域
    area_id = request.form.get('area_id')
    if all([title, facilities]):
        # 创建房屋信息
        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.user_id = user_id
        house.area_id = area_id
        # 保存房屋对应的设施
        for fac_id in facilities:
            fac = Facility.query.get(fac_id)
            house.facilities.append(fac)
        house.add_update()
        return jsonify({'code': 200, 'msg': '添加房屋信息成功', 'data': house.id})
    return jsonify({'code': 1001, 'msg': '请填写完整的房屋信息!'})
コード例 #10
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)
コード例 #11
0
def add_house():
    user_id = int(session['user_id'])
    title = request.form.get('title')
    price = request.form.get('price')
    area = 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')
    if not all([
            title, price, area, address, room_count, acreage, unit, capacity,
            beds, deposit, min_days, max_days
    ]):
        return jsonify(status_code.HOUSE_ERROR_INFO_IS_NULL)
    house = House()
    house.user_id = user_id
    house.title = title
    house.price = price
    house.area_id = area
    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 = int(max_days)

    facilitys = request.form.getlist('facility')

    for f in facilitys:
        facility = Facility.query.filter(Facility.id == f).first()
        house.facilities.append(facility)

    house.add_update()
    data = {'code': 200, 'house_id': house.id}
    return jsonify(data)
コード例 #12
0
ファイル: house_views.py プロジェクト: hyf1842838/ihome
def new_newhouse():
    # 1.获取数据
    tit = request.form.get('title')
    pri = request.form.get('price')
    ar_id = request.form.get('area_id')
    addr = request.form.get('address')
    room_co = request.form.get('room_count')
    are = request.form.get('acreage')
    uni = request.form.get('unit')
    cap = request.form.get('capacity')
    bed = request.form.get('beds')
    dep = request.form.get('deposit')
    min_day = request.form.get('min_days')
    max_day = request.form.get('max_days')
    fac = request.form.getlist('facility')

    if all([
            tit, pri, ar_id, addr, room_co, are, uni, cap, bed, dep, min_day,
            max_day, fac
    ]):
        # 2.获取用户并添加属性
        user_id = session['user_id']
        hous = House()
        hous.title = tit
        hous.price = pri
        hous.area_id = ar_id
        hous.address = addr
        hous.room_count = room_co
        hous.acreage = are
        hous.unit = uni
        hous.capacity = cap
        hous.beds = bed
        hous.deposit = dep
        hous.min_days = min_day
        hous.max_days = max_day
        hous.user_id = user_id

        for fac_id in fac:
            facility = Facility.query.get(fac_id)
            hous.facilities.append(facility)
        hous.add_update()
        return jsonify({'code': 200, 'msg': '请求成功', 'house_id': hous.id})
    return jsonify({'code': 2700, 'msg': '请填写完所有信息'})
コード例 #13
0
ファイル: house_views.py プロジェクト: sxrlt/my_blog
def new_house():
    if request.method == 'GET':
        return render_template('newhouse.html')
    if request.method == 'PATCH':
        user_id = session.get('user_id')
        user = User.query.filter(User.id == user_id).first()
        area_id = request.form.get('area_id')
        area = Area.query.filter(Area.id == area_id).first()
        title = request.form.get('title')
        price = request.form.get('price')
        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.get('facility')
        f_n = facility.split(',')
        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
        for i in f_n:
            if i == '':
                break
            house.facilities.append(Facility.query.get(int(i)))
        house.add_update()
        session['house_id'] = house.id
        return jsonify({'code': 200, 'msg': '请求成功'})
コード例 #14
0
ファイル: user_views.py プロジェクト: AmYEYU/aika_net_2
def my_newhouse():
    # 新建房源
    if request.method == 'POST':
        # 获取输入的信息
        house_title = request.form.get('house_title')
        house_price = request.form.get('house_price')
        area_id = request.form.get('area_id')
        house_address = request.form.get('house_address')
        house_room_count = request.form.get('house_room_count')
        house_acreage = request.form.get('house_acreage')
        house_unit = request.form.get('house_unit')
        house_capacity = request.form.get('house_capacity')
        house_beds = request.form.get('house_beds')
        house_deposit = request.form.get('house_deposit')
        house_min_days = request.form.get('house_min_days')
        house_max_days = request.form.get('house_max_days')
        user_id = session.get('user_id')
        # 创建房屋信息
        house = House()
        house.user_id = user_id
        house.area_id = area_id
        house.title = house_title
        house.price = house_price
        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.add_update()
        # 创建房屋设施
        checkbox_list = request.form.getlist('checkbox_list[]')
        for facility_id in checkbox_list:
            facility = Facility.query.get(facility_id)
            house.facilities.append(facility)
        db.session.commit()

        return jsonify({'code': 200, 'msg': '请求成功!', 'house_id': house.id})
コード例 #15
0
def my_newhouse():
    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()
    user = User.query.get(session['user_id'])

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

    for facilit in facility:
        fac = Facility.query.filter_by(id=facilit).first()
        house.facilities.append(fac)
        db.session.commit()

    house.add_update()

    return jsonify({'code': 200, 'msg': 'ok', 'house_id':house.id})
コード例 #16
0
ファイル: home_views.py プロジェクト: cmname/ihome
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})
コード例 #17
0
ファイル: home_views.py プロジェクト: posion123/ihome
def my_newhouse():
    facilitys = request.form.getlist('facility')
    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')
    user_id = session.get('user_id')

    house = House()
    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
    house.user_id = user_id
    house.add_update()
    facility = []
    for i in facilitys:
        facility.append(Facility.query.filter_by(id=int(i)).first())

    house.facilities = facility
    house.add_update()

    return jsonify({'code': 200, 'msg': '请求成功', 'data': house.id})
コード例 #18
0
def my_newhouse():
    # 获取参数
    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')
    facilitys = request.form.getlist('facility')
    if not all([title, price, area_id, address, room_count, acreage, unit, capacity,
                beds, deposit, min_days, max_days, facilitys]):
        return jsonify({'code': 1001, 'msg': '请将全部信息填写完整后再提交'})
    house = House()
    house.user_id = current_user.id
    house.price = price
    house.title = title
    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
    for facilitie_id in facilitys:
        facility = Facility.query.get(facilitie_id)
        house.facilities.append(facility)
    # 房屋的设施
    house.add_update()
    house_id = house.id
    return jsonify({'code':200,'data':house_id})
コード例 #19
0
def x_house():
    # 获取数据
    title = request.form.get('title')
    price = request.form.get('price')
    area_id = request.form.get('area_id')
    addres = request.form.get('addres')
    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')
    facilities_f = request.form.getlist('facility')
    # 保存数据
    user_id = session.get('user_id')
    house = House()
    house.user_id = user_id
    house.title = title
    house.price = price
    house.area_id = area_id
    house.address = addres
    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

    for facility_id in facilities_f:
        facility = Facility.query.get(facility_id)
        # 多对多关联
        house.facilities.append(facility)
    house.add_update()
    session['house_id'] = house.id
    return jsonify({'code': 200})
コード例 #20
0
ファイル: house_views.py プロジェクト: clm-D/knowledge
def newhouse_post():
    house = House()
    house.user_id = session['user_id']
    house.title = request.form.get('title')
    house.price = request.form.get('price')
    house.area_id = request.form.get('area_id')
    house.address = request.form.get('address')
    house.room_count = request.form.get('room_count')
    house.acreage = 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 = request.form.get('min_days')
    house.max_days = request.form.get('max_days')

    facilitys = request.form.getlist('facility')
    for facility_id in facilitys:
        facility = Facility.query.get(facility_id)
        house.facilities.append(facility)
    house.add_update()

    return jsonify({'code': status_code.OK, 'house_id': house.id})
コード例 #21
0
ファイル: house_views.py プロジェクト: b02330224/nongfangwang
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)
コード例 #22
0
ファイル: home_views.py プロジェクト: xiaopengpeng1/MyProject
def add_newhouse():
    if request.method == 'POST':
        title = request.form.get('title')
        price = request.form.get('price')
        area = request.form.get('area_id')
        addr = request.form.get('address')
        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.title = title
        house.price = price
        house.area_id = area
        house.address = addr
        house.room_count = 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.user_id = session['user_id']
        for i in facility:
            fac = Facility.query.filter_by(id=int(i)).first()
            house.facilities.append(fac)
        house.add_update()

        id = house.id
        return jsonify({'code': 200, 'msg': '请求成功', 'id': id})
コード例 #23
0
def my_new_house():
    house = House()
    house.user_id = session.get('user_id')
    house.title = request.form.get('title')
    house.price = request.form.get('price')
    house.area_id = request.form.get('area_id')
    house.address = request.form.get('address')
    house.room_count = request.form.get('room_count')
    house.acreage = 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 = request.form.get('min_days')
    house.max_days = request.form.get('max_days')
    facilities = request.form.getlist('facility')
    for facility_id in facilities:
        facility = Facility.query.get(facility_id)
        house.facilities.append(facility)
    try:
        house.add_update()
        return jsonify(code=status_code.OK, house_id=house.id)
    except:
        return jsonify(status_code.DATABASE_ERROR)
コード例 #24
0
def new_house_p():
    """
    新房源创建 - 房间信息、图片、基础设置
    需要用到house、facility模型
    [('title', 'title'), ('price', '123'), ('area_id', '2'),
    ('address', '12'), ('room_count', '1'), ('acreage', '1'),
    ('unit', '1'), ('capacity', '1'), ('beds', '1'),
    ('deposit', '1'), ('min_days', '1'), ('max_days', '1'),
    ('facility', '1'), ('facility', '3'), ('facility', '5')]
    """
    if request.method == 'POST':
        user_id = session.get('user_id')
        title = request.form.get('title')
        price = int(request.form.get('price'))
        area_id = int(request.form.get('area_id'))
        address = request.form.get('address')
        room_count = int(request.form.get('room_count'))
        acreage = int(request.form.get('acreage'))
        unit = request.form.get('unit')
        capacity = int(request.form.get('capacity'))
        beds = request.form.get('beds')
        deposit = int(request.form.get('deposit'))
        min_days = int(request.form.get('min_days'))
        max_days = int(request.form.get('max_days'))
        facilities = request.form.getlist('facility')
        # 参数没填写完就重新填写
        if not all([
                title, price, area_id, address, room_count, acreage, unit,
                capacity, beds, deposit, min_days, facilities, user_id
        ]):
            return jsonify(status.USER_PARAMS_IS_INVALID)
        # 给house模型添加数据
        house_n = House()
        house_n.user_id = user_id
        house_n.title = title
        house_n.price = price
        house_n.area_id = area_id
        house_n.address = address
        house_n.room_count = room_count
        house_n.acreage = acreage
        house_n.unit = unit
        house_n.capacity = capacity
        house_n.beds = beds
        house_n.deposit = deposit
        house_n.min_days = min_days
        house_n.max_days = max_days
        # 添加基础设施对象:循环拿出基础设置对象,将对象添加到中间表
        for i in facilities:
            facility = Facility.query.filter(Facility.id == int(i)).first()
            house_n.facilities.append(facility)
        house_n.add_update()
        house_id = house_n.id
        return jsonify({'code': 500, 'msg': '添加房间成功', 'house_id': house_id})

    if request.method == 'PATCH':
        """取得房间id和房间图片,对房间id和房间图片进行储存,添加首图"""
        house_id = request.form.get('house_id')
        house_image = request.files.get('house_image')
        if not all([house_id, house_image]):
            return jsonify(status.IMAGE_OR_HOUSE_ID_INVALID)

        path = os.path.join(MEDIA_PATH, house_image.filename)
        house_image.save(path)

        house_image_n = HouseImage()
        house_image_n.url = house_image.filename
        house_image_n.house_id = house_id
        house_image_n.add_update()

        # 添加首图
        house = House.query.filter(House.id == house_id).first()
        if house.index_image_url:
            data = {'code': 200, 'url': house_image.filename}
            return jsonify(data)

        images = HouseImage.query.filter(
            HouseImage.house_id == house_id).order_by('create_time').first()
        house.index_image_url = images.url
        house.add_update()

        data = {'code': 200, 'url': house_image.filename}
        return jsonify(data)
コード例 #25
0
ファイル: newhouse.py プロジェクト: JokerHai/ihome
def newhouse():
    if request.method == 'GET':
        data = {'title': '测试'}
        # 5. 返回响应
        return render_template('house/newhouse.html', house=data)

    elif request.method == "POST":
        # 1.获取参数
        if not current_user.is_authenticated:
            return jsonify(errno=RET.DBERR, errmsg="未登录")
        user_id = current_user.id
        title = request.json.get("title")
        price = request.json.get("price")
        area_id = request.json.get("area_id")
        address = request.json.get("address")
        room_count = request.json.get("room_count")
        acreage = request.json.get("acreage")
        unit = request.json.get("unit")
        capacity = request.json.get("capacity")
        beds = request.json.get("beds")
        deposit = request.json.get("deposit")
        min_days = request.json.get("min_days")
        max_days = request.json.get("max_days")
        facility = request.json.get("facility")

        # 2. 校验参数,为空校验
        if not all([
                title, price, area_id, address, room_count, acreage, unit,
                capacity, beds, deposit, min_days, max_days, facility
        ]):
            return jsonify(errno=RET.PARAMERR, errmsg="参数不全")

        # 3.判断城区id是否存在
        try:
            area = Area.query.get(area_id)
        except Exception as e:
            current_app.logger.error(e)
            return jsonify(errno=RET.DBERR, errmsg="数据库异常")

        if area is None:
            return jsonify(errno=RET.NODATA, errmsg="城区信息有误")

        # 4. 创建房源对象,设置属性
        house = House()
        house.user_id = user_id
        # def after_request(resp):
        #     # 调用系统方法,获取csrf_token
        #     csrf_token = generate_csrf()
        #
        #     # 将csrf_token设置到cookie中
        #     resp.set_cookie("csrf_token", csrf_token)
        #
        #     return resp
        # 注册蓝图
        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

        # 4. 保存到数据
        try:
            db.session.add(house)
            db.session.commit()
        except Exception as e:
            current_app.logger.error(e)
            return jsonify(errno=RET.DBERR, errmsg="房源发布失败")
コード例 #26
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})