Esempio n. 1
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.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')

    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 Exception as e:
        return jsonify(status_code.DATABASE_ERROR)
Esempio n. 2
0
def my_new_house():

    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')

    # 配套设施
    facilitys = house_dict.getlist('facility')

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

    user = User.query.get(session['user_id'])
    house = House()
    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 = max_days
    house.max_days = max_days

    try:
        house.add_update()
        hou = House.query.get(house.id)
        for facility in facilitys:
            fac = Facility.query.get(facility)
            hou.facilities.append(fac)
            db.session.add(hou)
        db.session.commit()
        return jsonify(status_code.SUCCESS)
    except Exception as e:
        return jsonify(status_code.DATABASE_ERROR)