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


Python Place.select方法代码示例

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


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

示例1: handle_amenity_for_place

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import select [as 别名]
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,代码行数:36,代码来源:amenity.py

示例2: books

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import select [as 别名]
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,代码行数:60,代码来源:place_book.py

示例3: places

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import select [as 别名]
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,代码行数:29,代码来源:place.py

示例4: get_place_amenities

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import select [as 别名]
def get_place_amenities(place_id):
    """
    Get amenities for place
    Return a list of all amenities for a place
    ---
    tags:
        - Amenity
    parameters:
        -
            in: path
            name: place_id
            type: string
            required: True
            description: ID of the place
    responses:
        200:
            description: List of all amenities for the place
            schema:
                $ref: '#/definitions/get_amenities_get_Amenities'
    """
    try:
        ''' Check if the place exists '''
        query = Place.select().where(Place.id == place_id)
        if not query.exists():
            raise LookupError('place_id')

        ''' Return amenities for the given place '''
        data = Amenity.select().join(PlaceAmenities).where(PlaceAmenities.place == place_id)
        return ListStyle.list(data, request), 200
    except LookupError as e:
        abort(404)
    except Exception as e:
        abort(500)
开发者ID:rickharris-dev,项目名称:airbnb_clone,代码行数:35,代码来源:amenity.py

示例5: get_places

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import select [as 别名]
def get_places():
    """
    Get all places
    List all places in the database.
    ---
    tags:
        - Place
    responses:
        200:
            description: List of all places
            schema:
                id: Places
                required:
                    - data
                    - paging
                properties:
                    data:
                        type: array
                        description: places array
                        items:
                            $ref: '#/definitions/get_place_get_Place'
                    paging:
                        description: pagination
                        schema:
                            $ref: '#/definitions/get_amenities_get_Paging'
    """
    data = Place.select()
    return ListStyle.list(data, request), 200
开发者ID:rickharris-dev,项目名称:airbnb_clone,代码行数:30,代码来源:place.py

示例6: subtest_createWithAllParams

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import select [as 别名]
    def subtest_createWithAllParams(self):
        """
        Test proper creation of a place record upon POST request to the API
        with all parameters provided.
        """
        POST_request1 = self.createPlaceViaAPI()
        self.assertEqual(POST_request1.status[:3], '200')

        now = datetime.now().strftime('%d/%m/%Y %H:%M')

        # self.assertEqual(Place.get(Place.id == 1).owner.id, 1)
        # self.assertEqual(Place.get(Place.id == 1).city.id, 1)
        # self.assertEqual(Place.get(Place.id == 1).name, "foo")
        # self.assertEqual(Place.get(Place.id == 1).description, "foo description")
        # self.assertEqual(Place.get(Place.id == 1).number_rooms, 1)
        # self.assertEqual(Place.get(Place.id == 1).number_bathrooms, 1)
        # self.assertEqual(Place.get(Place.id == 1).max_guest, 1)
        # self.assertEqual(Place.get(Place.id == 1).price_by_night, 1)
        # self.assertEqual(Place.get(Place.id == 1).latitude, 22.0)
        # self.assertEqual(Place.get(Place.id == 1).longitude, 22.0)
        # self.assertEqual(Place.get(Place.id == 1).created_at.strftime('%d/%m/%Y %H:%M'), now)
        # self.assertEqual(Place.get(Place.id == 1).updated_at.strftime('%d/%m/%Y %H:%M'), now)

        # test that place ID for sole record in database is correct
        self.assertEqual(Place.select().get().id, 1)
开发者ID:WilliamMcCann,项目名称:airbnb_clone,代码行数:27,代码来源:place.py

示例7: modify_place

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import select [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

示例8: create_new_booking

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import select [as 别名]
def create_new_booking(place_id):
    content = request.get_json()
    if not all(param in content.keys() for param in ["user", "is_validated", "date_start", "number_nights"]):
        #ERROR
        return "Failed: bad input"
    try:
        users = User.select().where(User.id == int(user_id))
        user = None
        for u in users:
            user = u
        if user == None:
            return "Failed, user does not exist"

        places = Place.select().where(Place.id == int(place_id))
        place = None
        for u in places:
            place = u
        if place == None:
            return "Failed, place does not exist"

        placebook = PlaceBook()
        placebook.user = user
        placebook.place = place
        placebook.is_validated = content["is_validated"]
        placebook.date_start = content["date_start"]
        placebook.number_nights = content["number_nights"]
        placebook.save()
    except Exception as e:
        return "Failed"
    return "Success"
开发者ID:Praylin,项目名称:airbnb_clone,代码行数:32,代码来源:place_book.py

示例9: place_amenity_id

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import select [as 别名]
def place_amenity_id(place_id, amenity_id):
	query = Place.select().where(Place.id == place_id)

	if query.wrapped_count() < 1:
		return json_response(status_=404, msg="that place does not exist")

	query = Amenity.select().where(Amenity.id == amenity_id)

	if query.wrapped_count() < 1:
		return json_response(status_=404, msg="that amenity does not exist")

	query = PlaceAmenities.select().where(PlaceAmenities.amenity == amenity_id, PlaceAmenities.place == place_id)

	if query.wrapped_count() > 0:
		return json_response(status_=404, msg="amenity already set for given place")

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

	elif request.method == "DELETE":
		amenity = PlaceAmenities.get(PlaceAmenities.amenity == amenity_id, PlaceAmenities.place == place_id)
		amenity.delete_instance()
		amenity.save()
		return json_response(status_=200, msg="amentiy delete for given place")
开发者ID:jdeepee,项目名称:airbnb_clone,代码行数:28,代码来源:amenity.py

示例10: update_place

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import select [as 别名]
 def update_place(book, place_id):
     places = Place.select().where(Place.id == int(place_id))
     place = None
     for u in places:
         place = u
     if place == None:
         return error_msg(400, 400, "place does not exist")
     book.place = place
开发者ID:johnSerrano,项目名称:airbnb_clone,代码行数:10,代码来源:place_book.py

示例11: update_place

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import select [as 别名]
 def update_place(book, place_id):
     places = Place.select().where(Place.id == int(place_id))
     place = None
     for u in places:
         place = u
     if place == None:
         return "Failed, place does not exist"
     book.place = place
开发者ID:Praylin,项目名称:airbnb_clone,代码行数:10,代码来源:place_book.py

示例12: state_places

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import select [as 别名]
def state_places(state_id):
	state = State.select().where(State.id == state_id)

	if state.wrapped_count() < 1:
		return json_response(status_=404, code=10002, msg="state not found")

	query = Place.select().join(City).join(State).where(State.id == state_id)

	return ListStyle.list(query, request)
开发者ID:jdeepee,项目名称:airbnb_clone,代码行数:11,代码来源:place.py

示例13: delete_booking

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import select [as 别名]
def delete_booking(place_id, book_id):
    """
    Delete the given booking
    Deletes the given booking in the database.
    ---
    tags:
        - PlaceBook
    parameters:
        -
            in: path
            name: place_id
            type: integer
            required: True
            description: ID of the place
        -
            in: path
            name: book_id
            type: integer
            required: True
            description: ID of the booking
    responses:
        200:
            description: Booking deleted successfully
            schema:
                $ref: '#/definitions/delete_amenity_delete_delete_200'
        404:
            description: Booking was not found
        500:
            description: Request could not be processed
    """
    try:
        ''' Test if place does not exist '''
        query = Place.select().where(Place.id == place_id)
        if not query.exists():
            raise LookupError('place_id')

        ''' Test if booking does not exist '''
        query = PlaceBook.select().where(PlaceBook.id == book_id)
        if not query.exists():
            raise LookupError('book_id')

        ''' Check if place, booking combo exists '''
        query = query.where(PlaceBook.place == place_id)
        if not query.exists():
            raise LookupError('book_id, place_id')

        ''' Delete the given booking '''
        booking = PlaceBook.delete().where(PlaceBook.id == book_id, PlaceBook.place == place_id)
        booking.execute()
        res = {}
        res['code'] = 200
        res['msg'] = "Booking was deleted successfully"
        return res, 200
    except LookupError as e:
        abort(404)
    except Exception as e:
        abort(500)
开发者ID:rickharris-dev,项目名称:airbnb_clone,代码行数:59,代码来源:place_book.py

示例14: places

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import select [as 别名]
def places():
	if request.method == 'GET':
		list_places = Place.select()
		
		return ListStyle.list(list_places, request), 200

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

		test = Place.select().where(Place.name == request.form["name"])

		if test.wrapped_count() > 0:
			return json_response(status_=409, code=10002, msg="place already exists with this name")

		try:
			entry = Place(owner=request.form["owner_id"], name=request.form["name"], city=request.form["city"])

			if request.form['description']:
				entry.description = str(request.form['description'])

			if request.form['number_rooms']:
				entry.number_rooms = int(request.form['number_rooms'])

			if request.form['number_bathrooms']:
				entry.number_bathrooms = int(request.form['number_bathrooms'])

			if request.form['max_guest']:
				entry.max_guest = int(request.form['max_guest'])

			if request.form['price_by_night']:
				entry.price_by_night = int(request.form['price_by_night'])

			if request.form['latitude']:
				entry.latitude = float(request.form['latitude'])

			if request.form['longitude']:
				entry.longitude = float(request.form['longitude'])

			entry.save()
			return jsonify(entry.to_dict()), 201

		except IntegrityError:
			return json_response(status_=400, msg="you are missing a field in your post request")
开发者ID:jdeepee,项目名称:airbnb_clone,代码行数:46,代码来源:place.py

示例15: places_by_city

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import select [as 别名]
def places_by_city(state_id, city_id):
    try:
       city_query = City.get(City.id == city_id, City.state == state_id)
    except:
        return {"code":404, "msg":"not found"}, 404
    places = []
    query = Place.select().where(Place.city == city_query.id)
    for place in query:
        places.append(place.to_hash())
    return jsonify(places)
开发者ID:madejean,项目名称:airbnb_clone,代码行数:12,代码来源:place.py


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