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


Python place.Place类代码示例

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


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

示例1: create_database

def create_database():
    try:
         User.create_table()
    except peewee.OperationalError:
        pass

    try:
         State.create_table()
    except peewee.OperationalError:
        pass

    try:
         City.create_table()
    except peewee.OperationalError:
        pass

    try:
         Place.create_table()
    except peewee.OperationalError:
        pass

    try:
         PlaceBook.create_table()
    except peewee.OperationalError:
        pass

    try:
         Amenity.create_table()
    except peewee.OperationalError:
        pass

    try:
         PlaceAmenities.create_table()
    except peewee.OperationalError:
        pass
开发者ID:johnSerrano,项目名称:airbnb_clone,代码行数:35,代码来源:migrate.py

示例2: modify_place

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,代码行数:30,代码来源:place.py

示例3: test_review_place3

    def test_review_place3(self):
        # Creating a setUp
        new_state = State(name='California')
        new_state.save()
        new_city = City(name='San Francisco', state=1)
        new_city.save()
        new_place = Place(owner=1,
                          city=1,
                          name="Steven",
                          description="house",
                          number_rooms=3,
                          number_bathrooms=2,
                          max_guest=3,
                          price_by_night=100,
                          latitude=37.774929,
                          longitude=-122.419416)
        new_place.save()

        # Creating a review for a place that exist
        new_review = self.app.post('/places/1/reviews',
                                   data=dict(message="I like it",
                                             stars=5))
        assert new_review.status_code == 200

        # Checking for a review that does not exist
        new_review_get = self.app.get('/places/1/reviews/5')
        assert new_review_get.status_code == 404

        # Checking for a place that does not exist
        new_review_get = self.app.get('/places/2/reviews/2')
        assert new_review_get.status_code == 404

        # Checking for a review that does exist
        new_review_get = self.app.get('/places/1/reviews/1')
        assert new_review_get.status_code == 200
开发者ID:frakentoaster,项目名称:airbnb_clone,代码行数:35,代码来源:review.py

示例4: places

def places():
    """Handle GET and POST requests to /places route.

    Return a list of all places in the database in the case of a GET request.
    Create a new place record in the database in the case of a POST request.
    """
    # handle GET requests:
    # --------------------------------------------------------------------------
    if request.method == 'GET':
        list = ListStyle.list(Place.select(), request)
        return jsonify(list)

    # handle POST requests:
    # --------------------------------------------------------------------------
    elif request.method == 'POST':
        record = Place( owner=request.form['owner_id'],
                        city=request.form['city_id'],
                        name=request.form['name'],
                        description=request.form['description'],
                        number_rooms=request.form['number_rooms'],
                        number_bathrooms=request.form['number_bathrooms'],
                        max_guest=request.form['max_guest'],
                        price_by_night=request.form['price_by_night'],
                        latitude=request.form['latitude'],
                        longitude=request.form['longitude'] )
        record.save()
        return jsonify(record.to_hash())
开发者ID:ronachong,项目名称:airbnb_clone,代码行数:27,代码来源:place.py

示例5: test_review_place2

    def test_review_place2(self):
        # Creating a setUp
        new_state = State(name='California')
        new_state.save()
        new_city = City(name='San Francisco', state=1)
        new_city.save()
        new_place = Place(owner=1,
                          city=1,
                          name="Steven",
                          description="house",
                          number_rooms=3,
                          number_bathrooms=2,
                          max_guest=3,
                          price_by_night=100,
                          latitude=37.774929,
                          longitude=-122.419416)
        new_place.save()

        # Creating a review for a place that exist
        new_review = self.app.post('/places/1/reviews',
                                   data=dict(message="I like it",
                                             stars=5))
        assert new_review.status_code == 200
        # checking the review id, should be 1
        assert json.loads(new_review.data)["id"] == 1
        # Creating a review for a place that does not exist
        new_review = self.app.post('/places/3/reviews',
                                   data=dict(message="I like it",
                                             user_id=1,
                                             stars=5))
        assert new_review.status_code == 404
开发者ID:frakentoaster,项目名称:airbnb_clone,代码行数:31,代码来源:review.py

示例6: tearDown

 def tearDown(self):
     #delete all from users
     PlaceBook.delete().execute()
     Place.delete().execute()
     User.delete().execute()
     City.delete().execute()
     State.delete().execute()
开发者ID:johnSerrano,项目名称:airbnb_clone,代码行数:7,代码来源:place_book.py

示例7: setUp

    def setUp(self):
        # disabling logs
        logging.disable(logging.CRITICAL)
        self.app = app.test_client()
        # connecting to the database
        db.connect()
        # creating tables
        db.create_tables([User], safe=True)
        db.create_tables([State], safe=True)
        db.create_tables([City], safe=True)
        db.create_tables([Place], safe=True)
        db.create_tables([PlaceBook], safe=True)

        # Creating a setUp
        new_state = State(name='California')
        new_state.save()
        new_city = City(name='San Francisco', state=1)
        new_city.save()
        # Creating a new users
        user1 = User(first_name='Jon',
                     last_name='Snow',
                     email='[email protected]',
                     password='toto1234')
        user1.save()
        new_place = Place(owner=1,
                          city=1,
                          name="Steven",
                          description="house",
                          number_rooms=3,
                          number_bathrooms=2,
                          max_guest=3,
                          price_by_night=100,
                          latitude=37.774929,
                          longitude=-122.419416)
        new_place.save()
开发者ID:frakentoaster,项目名称:airbnb_clone,代码行数:35,代码来源:place_book.py

示例8: setUp

 def setUp(self):
     #connect to db and delete everyone in the users table
     PlaceBook.delete().execute()
     Place.delete().execute()
     User.delete().execute()
     City.delete().execute()
     State.delete().execute()
开发者ID:johnSerrano,项目名称:airbnb_clone,代码行数:7,代码来源:place_book.py

示例9: make_reservation

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,代码行数:35,代码来源:place.py

示例10: find_book

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,代码行数:60,代码来源:place_book.py

示例11: handle_amenity_for_place

def handle_amenity_for_place(place_id, amenity_id):
    '''Add the amenity with `amenity_id` to the place with `place_id` with a
    POST request. Delete the amenity with the id of `amenity_id` with a DELETE
    request.

    Keyword arguments:
    place_id -- The id of the place.
    amenity_id -- The id of the amenity.
    '''
    try:
        Amenity.select().where(Amenity.id == amenity_id).get()
    except Amenity.DoesNotExist:
        return jsonify(msg="Amenity does not exist."), 404
    try:
        Place.select().where(Place.id == place_id).get()
    except Place.DoesNotExist:
        return jsonify(msg="Place does not exist."), 404

    if request.method == 'POST':
        '''Save the connection in the ReviewPlace table.'''
        PlaceAmenities().create(place=place_id, amenity=amenity_id)

        return jsonify(msg="Amenity added to place successfully."), 201

    elif request.method == 'DELETE':
        (PlaceAmenities
         .delete()
         .where((PlaceAmenities.place == place_id) &
                (PlaceAmenities.amenity == amenity_id))
         .execute())

        Amenity.delete().where(Amenity.id == amenity_id).execute()

        return jsonify(msg="Amenity deleted successfully."), 200
开发者ID:Siphan,项目名称:airbnb_clone,代码行数:34,代码来源:amenity.py

示例12: books

def books(place_id):
	if request.method == 'GET':
		query = Place.select().where(Place.id == place_id)

		if not query.exists():
			return json_response(status_=404, msg="place does not exist")

		query = PlaceBook.select().where(PlaceBook.place == place_id)
		return ListStyle.list(query, request), 200

	elif request.method == 'POST':
		if "name" not in request.form or "date_start" not in request.form:
			return json_response(status_=400, code=40000, msg="missing parameters")

		test = Place.select().where(Place.id == place_id)

		if test.wrapped_count() < 1:
			return json_response(status_=404, code=10002, msg="no place with such id")

		test = User.select().where(User.id == request.form["user"])

		if test.wrapped_count() < 1:
			return json_response(status_=404, msg="no user with given id")

		try:
			start = datetime.strptime(request.form['date_start'], '%Y/%m/%d %H:%M:%S')

		except ValueError:
			return json_response(status_=400, msg="incorrect date format")

		end = start + timedelta(days=int(request.form['number_nights']))
		bookings = PlaceBook.select().where(PlaceBook.place == place_id)

		for booking in bookings:
			start_b = booking.date_start
			end_b = start_date + timedelta(days=booking.number_nights)

			if start >= start_b and start < end_b:
				return json_response(status=410, msg="Place unavailable at this date", code=110000)

			elif start_b >= start and start_b < end:
				return json_response(status=410, msg="Place unavailable at this date", code=110000)

			elif end > start_b  and end <= end_b:
				return json_response(status=410, msg="Place unavailable at this date", code=110000)

		place_book = PlaceBook(place=place_id,
								user=request.form['user'],
								date_start=datetime.strptime(request.form['date_start'], '%Y/%m/%d %H:%M:%S'))

		if "is_validated" in request.form:
			place_book.is_validated = request.form["is_validated"]

		elif "number_nights" in request.form:
			place_book.number_nights = request.form["number_nights"]

		place_book.save()
		return jsonify(place_book.to_dict()), 201
开发者ID:jdeepee,项目名称:airbnb_clone,代码行数:58,代码来源:place_book.py

示例13: tearDown

 def tearDown(self):
     """
     Remove place table from airbnb_test database upon completion of test
     case.
     """
     Place.drop_table()
     City.drop_table()
     State.drop_table()
     User.drop_table()
开发者ID:WilliamMcCann,项目名称:airbnb_clone,代码行数:9,代码来源:place.py

示例14: place_id

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,代码行数:56,代码来源:place.py

示例15: tearDown

 def tearDown(self):
     """
     Remove placebook table from airbnb_test database upon completion of
     test case.
     """
     # drop tables from database
     PlaceBook.drop_table()
     Place.drop_table()
     City.drop_table()
     State.drop_table()
     User.drop_table()
开发者ID:WilliamMcCann,项目名称:airbnb_clone,代码行数:11,代码来源:place_book.py


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