当前位置: 首页>>代码示例>>Python>>正文


Python Place.get方法代码示例

本文整理汇总了Python中app.models.place.Place.get方法的典型用法代码示例。如果您正苦于以下问题:Python Place.get方法的具体用法?Python Place.get怎么用?Python Place.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app.models.place.Place的用法示例。


在下文中一共展示了Place.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: modify_place

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import get [as 别名]
def modify_place(place_id):
    id = place_id
    if request.method == 'GET':
        try:
            get_place = Place.get(Place.id == id).to_dict()
            return jsonify(get_place)
        except:
            return make_response(jsonify({'code': '10001',
                                          'msg': 'Place not found'}), 404)
    elif request.method == 'PUT':
        place = Place.select().where(Place.id == place_id).get()
        params = request.values
        for key in params:
            if key == 'owner' or key == 'city':
                return jsonify(msg="You may not update the %s." % key), 409
            if key == 'updated_at' or key == 'created_at':
                continue
            else:
                setattr(place, key, params.get(key))
        place.save()
        return jsonify(msg="Place information updated successfully."), 200

    elif request.method == 'DELETE':
        try:
            get_place = Place.get(Place.id == id)
            get_place.delete_instance()
            return "Place with id = %d was deleted\n" % (int(id))
        except:
            return make_response(jsonify({'code': '10001',
                                          'msg': 'Place not found'}), 404)
开发者ID:frakentoaster,项目名称:airbnb_clone,代码行数:32,代码来源:place.py

示例2: make_reservation

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import get [as 别名]
def make_reservation(place_id):
    try:
        Place.get(Place.id == place_id)
    except Place.DoesNotExist:
            return make_response(jsonify({'code': '10001',
                                          'msg': 'Place not found'}), 404)
    if request.method == "POST":
        year = int(request.form["year"])
        month = int(request.form["month"])
        day = int(request.form["day"])

        try:
            # getting the place
            get_booking = PlaceBook.get(PlaceBook.place == place_id)

            # Creating a datetime with the post parameters
            date_object = datetime(year, month, day).strftime("%d/%m/%Y")

            # getting the date from start and formatting its
            date = get_booking.to_dict()['date_start'].strftime("%d/%m/%Y")

            # Getting the duration of the booking
            duration = get_booking.to_dict()['number_nights']

            # Getting the exact day of checkout
            total_days = (get_booking.to_dict()['date_start'] +
                          timedelta(duration)).strftime("%d/%m/%Y")

            if date_object >= date and date_object <= total_days:
                return jsonify({'Available': False})
            else:
                return jsonify({'Available': True})
        except:
            return make_response(jsonify({'code': '10001',
                                          'msg': 'Wrong date format'}), 400)
开发者ID:frakentoaster,项目名称:airbnb_clone,代码行数:37,代码来源:place.py

示例3: find_book

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import get [as 别名]
def find_book(place_id):
    # Checking if the place exist
    try:
        Place.get(Place.id == place_id)
    except Place.DoesNotExist:
        return jsonify({'code': 404, 'msg': 'Place not found'}), 404

    if request.method == "GET":
        try:
            # Selecting the place booked
            list = ListStyle.list(PlaceBook.select()
                                  .where(PlaceBook.place == place_id), request)
            return jsonify(list)
        except:
            return jsonify({'code': 404, 'msg': 'Book not found'}), 404
    if request.method == "POST":
        # cheking if there is a place
        try:
            Place.get(Place.id == place_id)
        except Place.DoesNotExist:
            return jsonify({'code': 404, 'Place not found': 'hello'}), 404

        try:
            # getting the place
            get_booking = PlaceBook.get(PlaceBook.place == place_id)

            # getting the date from start and formatting its
            date = get_booking.to_dict()['date_start']  # .strftime("%d/%m/%Y")

            # Getting the duration of the booking
            duration = get_booking.to_dict()['number_nights']

            # Getting the exact day of checkout
            total_days = (get_booking.to_dict()['date_start'] +
                          timedelta(duration))  # .strftime("%d/%m/%Y")
            # Create a new booking from POST data for a selected place
        except:
            date = datetime(2000, 01, 01)
            total_days = datetime(2000, 01, 01)
        # try:

        get_user = request.form['user_id']
        get_date = request.form['date_start']
        get_nights = int(request.form['number_nights'])

        # formatting the date from unicode to datetime
        to_date = datetime.strptime(get_date, '%Y-%m-%d %H:%M:%S')

        # Checking if the place is Available in the desired dates
        if to_date >= date and to_date <= total_days:
            return make_response(
                   jsonify({'code': '110000',
                            'msg': "Place unavailable at this date"}), 410)
        # Booking the place since it is Available
        new_book = PlaceBook(place=place_id,
                             user=get_user,
                             date_start=get_date,
                             number_nights=get_nights)
        new_book.save()
        return jsonify(new_book.to_dict())
开发者ID:frakentoaster,项目名称:airbnb_clone,代码行数:62,代码来源:place_book.py

示例4: place_id

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import get [as 别名]
def place_id(place_id):
    """Handle GET, PUT, and DELETE requests to /places/<place_id> route.

    Return a hash of the appropriate record in the case of a GET request.
    Update appropriate hash in database in case of PUT request.
    Delete appropriate record in case of DELETE request.
    """
    # check whether resource exists:
    # --------------------------------------------------------------------------
    try:
        record = Place.get(Place.id == place_id)

    # return 404 not found if it does not
    except Place.DoesNotExist:
        return json_response(
            add_status_=False,
            status_=404,
            code=404,
            msg="not found"
        )

    # if exception does not arise:
    if request.method == 'GET':
        return jsonify(record.to_hash())

    # if exception does not arise:
    # --------------------------------------------------------------------------
    # handle GET requests
    elif request.method == 'PUT':
        record = Place.get(Place.id == place_id)
        # code below can be optimized in future using list comprehensions
        for key in request.values.keys():
            if key == "name":
                record.name = request.values[key]
            elif key == "description":
                record.description = request.values[key]
            elif key == "number_rooms":
                record.number_rooms = request.values[key]
            elif key == "number_bathrooms":
                record.number_bathrooms = request.values[key]
            elif key == "max_guest":
                record.max_guest = request.values[key]
            elif key == "price_by_night":
                record.price_by_night = request.values[key]
            elif key == "latitude":
                record.latitude = request.values[key]
            elif key == "longitude":
                record.longitude = request.values[key]
            record.save()
        return jsonify(record.to_hash())

    # handle DELETE requests
    elif request.method == "DELETE":
        record.delete_instance()
        record.save()
        return 'deleted city\n'
开发者ID:ronachong,项目名称:airbnb_clone,代码行数:58,代码来源:place.py

示例5: list_select_amenities

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import get [as 别名]
def list_select_amenities(place_id):
    try:
        Place.get(Place.id == place_id)
    except Place.DoesNotExist:
        return jsonify({'code': 404, 'msg': ' place not found'}), 404

    list = ListStyle.list(Amenity.select()
                          .join(PlaceAmenities)
                          .where(Amenity.id == PlaceAmenities.amenity)
                          .where(PlaceAmenities.place == place_id), request)

    return jsonify(list)
开发者ID:frakentoaster,项目名称:airbnb_clone,代码行数:14,代码来源:amenity.py

示例6: test_update

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import get [as 别名]
    def test_update(self):
        """
        test_update tests update of place records upon PUT requests to API
        """
        self.createPlaceViaPeewee()

        PUT_request1 = self.app.put('/places/1', data=dict(
            name="foo-name2",
            description="foo description 2",
            number_rooms=2,
            number_bathrooms=2,
            max_guest=2,
            price_by_night=2,
            latitude=30.0,
            longitude=32.0
        ))
        self.assertEqual(PUT_request1.status[:3], '200')

        self.assertEqual(Place.get(Place.id == 1).name, 'foo-name2')
        self.assertEqual(Place.get(Place.id == 1).description, 'foo description 2')
        self.assertEqual(Place.get(Place.id == 1).number_rooms, 2)
        self.assertEqual(Place.get(Place.id == 1).number_bathrooms, 2)
        self.assertEqual(Place.get(Place.id == 1).max_guest, 2)
        self.assertEqual(Place.get(Place.id == 1).price_by_night, 2)
        self.assertEqual(Place.get(Place.id == 1).latitude, 30.0)
        self.assertEqual(Place.get(Place.id == 1).longitude, 32.0)

        # test response of PUT request for place by place id which does not exist
        PUT_request2 = self.app.put('/places/1000')
        self.assertEqual(PUT_request2.status[:3], '404')
开发者ID:WilliamMcCann,项目名称:airbnb_clone,代码行数:32,代码来源:place.py

示例7: place

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import get [as 别名]
def place(place_id):
    if request.method == 'GET':
        try:
            new_place = Place.get(Place.id == place_id)
            return new_place.to_hash()
        except:
            return {'code':404, "msg":"not found"}, 404
    else:
        try:
            query = Place.get(Place.id == place_id)
        except:
            return {'code':404, "msg":"user does not exist"}, 404
        out_dict = query.to_hash()
        query.delete_instance()
        return out_dict
开发者ID:madejean,项目名称:airbnb_clone,代码行数:17,代码来源:place.py

示例8: put_place

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import get [as 别名]
def put_place(place_id):
    post_data = request.values
    try:
        place = Place.get(Place.id == place_id)
    except:
        return {"code":404, "msg":"not found"}, 404
    try:
        for key in post_data:
            if key == 'name':
                place.name = post_data[key]
            if key == 'description':
                place.description = post_data[key]
            if key == 'number_rooms':
                place.number_rooms = int(post_data[key])
            if key == 'number_bathrooms':
                place.number_bathrooms = int(post_data[key])
            if key == 'max_guest':
                place.max_guest = int(post_data[key])
            if key == 'price_by_night':
                place.price_by_night = int(post_data[key])
            if key == 'latitude':
                place.latitude = float(post_data[key])
            if key == 'longitude':
                place.longitude = float(post_data[key])
        place.save()
        return place.to_hash()
    except:
        return {"code":404, "msg":"not found"}, 404
开发者ID:madejean,项目名称:airbnb_clone,代码行数:30,代码来源:place.py

示例9: put_place

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import get [as 别名]
def put_place(place_id):
    post_data = request.values
    try:
        place = Place.get(Place.id == place_id)
    except Place.DoesNotExist:
        return {"code":404, "msg":"not found"}, 404
    
    if 'name' in post_data:
        place.name = post_data['name']
    if 'description' in post_data:
        place.description = post_data['description']
    if 'number_rooms' in post_data:
        place.number_rooms = int(post_data['number_rooms'])
    if 'number_bathrooms' in post_data:
        place.number_bathrooms = int(post_data['number_bathrooms'])
    if 'max_guest' in post_data:
        place.max_guest = int(post_data['max_guest'])
    if 'price_by_night' in post_data:
        place.price_by_night = int(post_data['price_by_night'])
    if 'latitude' in post_data:
        place.latitude = float(post_data['latitude'])
    if 'longitude' in post_data:
        place.longitude = float(post_data['longitude'])
    place.save()
    return place.to_dict()
开发者ID:bilalbarki,项目名称:airbnb_clone,代码行数:27,代码来源:place.py

示例10: get_place

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import get [as 别名]
def get_place(id):
    try:
        place = Place.get(Place.id == id)
    except Exception:
        return {'code': 404, 'msg': 'Place not found'}, 404

    return place.to_hash(), 200
开发者ID:havk64,项目名称:airbnb_clone,代码行数:9,代码来源:place.py

示例11: delete_single_place

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import get [as 别名]
def delete_single_place(place_id):
    try:
        query = Place.get(Place.id == place_id)
    except Place.DoesNotExist:
        return {'code':404, "msg":"place does not exist"}, 404
    out_dict = query.to_dict()
    query.delete_instance()
    return out_dict
开发者ID:bilalbarki,项目名称:airbnb_clone,代码行数:10,代码来源:place.py

示例12: delete_place

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import get [as 别名]
def delete_place(id):
    try:
        place = Place.get(Place.id == id)
    except Exception:
        return {'code': 404, 'msg': 'Place not found'}, 404

    place.delete_instance()
    return {'code': 200, 'msg': 'Deleted successfully'}, 200
开发者ID:havk64,项目名称:airbnb_clone,代码行数:10,代码来源:place.py

示例13: find_booking

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import get [as 别名]
def find_booking(place_id, book_id):
    # Checking if the place exist
    try:
        Place.get(Place.id == place_id)
    except Place.DoesNotExist:
        return jsonify({'code': 404, 'msg': 'Place not found'}), 404

    # Checking if the booking exist
    try:
        PlaceBook.get(PlaceBook.id == book_id)
    except PlaceBook.DoesNotExist:
        return jsonify({'code': 404, 'msg': 'Booking not found'}), 404
    # Find a booking
    try:
        booking = PlaceBook.get(PlaceBook.id == book_id and
                                PlaceBook.place == place_id)
        return jsonify(booking.to_dict())
    except:
        return jsonify({'code': 404, 'msg': 'not found'}), 404
开发者ID:frakentoaster,项目名称:airbnb_clone,代码行数:21,代码来源:place_book.py

示例14: delete_booking

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import get [as 别名]
def delete_booking(place_id, book_id):
    # Checking if the place exist
    try:
        Place.get(Place.id == place_id)
    except Place.DoesNotExist:
        return jsonify({'code': 404, 'msg': 'Place not found'}), 404

    # Checking if the booking exist
    try:
        PlaceBook.get(PlaceBook.id == book_id)
    except PlaceBook.DoesNotExist:
        return jsonify({'code': 404, 'msg': 'Booking not found'}), 404
    # Delete a booking
    try:
        booking = PlaceBook.get(PlaceBook.id == book_id and
                                PlaceBook.place == place_id)
        booking.delete_instance()
        return jsonify({'msg': 'Booked place was deleted'}), 200
    except:
        return jsonify({'code': 404, 'msg': 'not found'}), 404
开发者ID:frakentoaster,项目名称:airbnb_clone,代码行数:22,代码来源:place_book.py

示例15: update

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import get [as 别名]
def update(place_id, amenity_id):
    # Checking if place exist
    try:
        Place.get(Place.id == place_id)
    except Place.DoesNotExist:
        return jsonify({'code': 404, 'msg': 'Place not found'}), 404

    # Checking is Amenity exist
    try:
        Amenity.get(Amenity.id == amenity_id)
    except Amenity.DoesNotExist:
        return jsonify({'code': 404, 'msg': 'Amenity not found'}), 404

    if request.method == "POST":
        new_place_amenity = PlaceAmenities(place=place_id, amenity=amenity_id)
        new_place_amenity.save()
        return jsonify(new_place_amenity.amenity.to_dict())

    elif request.method == "DELETE":
        get_place_a = PlaceAmenities.get(PlaceAmenities.place == place_id and
                                         PlaceAmenities.amenity == amenity_id)
        get_place_a.delete_instance
        return "amenity deleted"
开发者ID:frakentoaster,项目名称:airbnb_clone,代码行数:25,代码来源:amenity.py


注:本文中的app.models.place.Place.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。