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)
def new_house(): if request.method == 'GET': return render_template('newhouse.html') if request.method == 'POST': # 获取房屋信息 house = House() house.user_id = current_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 id in facilities: facility = Facility.query.get(id) house.facilities.append(facility) house.add_update() return jsonify(code=status_code.OK, house_id=house.id)
def my_newhouse(): newhouse_info = request.form.to_dict() facilities = request.form.getlist('facility') user = User.query.filter_by(id=session['user_id']).first() house = House() # 向数据库存入数据 house.user_id = user.id house.title = newhouse_info['title'] house.area_id = newhouse_info['area_id'] house.price = newhouse_info['price'] house.address = newhouse_info['address'] house.room_count = newhouse_info['room_count'] house.acreage = newhouse_info['acreage'] house.unit = newhouse_info['unit'] house.capacity = newhouse_info['capacity'] house.beds = newhouse_info['beds'] house.deposit = newhouse_info['deposit'] house.min_days = newhouse_info['min_days'] house.max_days = newhouse_info['max_days'] for i in range(len(facilities)): f = Facility.query.filter_by(id=facilities[i]).first() house.facilities.append(f) house.add_update() house_id = House.query.filter_by(user_id=session['user_id'], title=newhouse_info['title']).first().id return jsonify({ 'code': 200, 'msg': '请求成功!', 'data': { 'house_id': house_id } })
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})
def add_house(): """ 添加新房源 :return: """ house = House() facilities = request.form.getlist('facility') if facilities: for facility_id in facilities: facility = Facility.query.get(facility_id) house.facilities.append(facility) 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') house.add_update() return jsonify({'code':200,'msg':'请求成功!','data':house.id})
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)
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})
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)
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)
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)
def user_new_house(): new_house_dict = request.form # 创建house house = House() house.title = new_house_dict['title'] house.price = new_house_dict['price'] house.area_id = new_house_dict['area_id'] house.address = new_house_dict['address'] house.room_count = new_house_dict['room_count'] house.acreage = new_house_dict['acreage'] house.unit = new_house_dict['unit'] house.capacity = new_house_dict['capacity'] house.beds = new_house_dict['beds'] house.deposit = new_house_dict['deposit'] house.min_days = new_house_dict['min_days'] house.max_days = new_house_dict['max_days'] # 判断数据是否填写完整 # 创建 try: house.add_update() except: return jsonify(status_code.ERRORS) # 创建ihome_house_facility facility_ids = new_house_dict['facilites'] for facility_id in facility_ids: facility = Facility.query.get(facility_id) house.facilities.add(facility) house.add_update() return jsonify(status_code.SUCCESS)
def my_newhouse(): # 保存房屋信息,设施信息 house_dict = request.form house = House() house.user_id = session['user_id'] house.price = house_dict.get('price') house.title = house_dict.get('title') 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') facilitys = house_dict.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)
def newhouse_info(): """ 发布新房源,修改数据库中的数据 :return: 当前状态房源的id """ house = House() house.user_id = session.get('user_id') house.title = request.form.get('title') house.price = request.form.get('price') house.area_id = int(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') house.add_update() facilities = request.form.getlist('facility') for facility_id in facilities: fac = Facility.query.filter(Facility.id == facility_id).first() house.facilities.append(fac) house.add_update() return jsonify({'code': 200, 'msg': '请求成功', 'data': house.id})
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)
def my_newhouse(): house_dict = request.form # 保存房屋信息, 设施信息 house = House() house.user_id = session['user_id'] # 获取用户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.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') # 最多入住天数 facilitys = house_dict.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)
def newhouse(): if request.method == 'GET': return render_template('newhouse.html') if request.method == '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') house.add_update() facility = request.form.getlist('facility') for fac in facility: f = Facility.query.get(fac) house.facilities.append(f) house.add_update() house_id = house.id return jsonify(code=200, house_id=house_id)
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})
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})
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})
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': '请填写完整的房屋信息!'})
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)
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': '请填写完所有信息'})
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)
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': '请求成功'})
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})
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})
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})
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})
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})
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})