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


Python Place.price_by_night方法代码示例

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


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

示例1: places

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

示例2: create_places

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import price_by_night [as 别名]
def create_places():
    """
    Create a place
    Creates a place based on post parameters.
    ---
    tags:
      - place
    parameters:
      - name: name
        in: query
        type: string
        description: name of the amenity to create
      - name: city
        in: query
        type: number
        description: id of the city the place is in
      - name: owner
        in: query
        type: number
        description: id of the owner of the place
      - name: description
        in: query
        type: string
        description: details about the place
      - name: number_rooms
        in: query
        type: number
        description: number of bedrooms in place
      - name: number_bathrooms
        in: query
        type: number
        description: number of bathrooms in place
      - name: max_guest
        in: query
        type: number
        description: max number of guests that can stay at a time
      - name: price_by_night
        in: query
        type: number
        description: price (in USD) to stay a night
      - name: latitude
        in: query
        type: float
        description: location of the place in latitude
      - name: longitude
        in: query
        type: float
        description: location of the place in longitude
    responses:
      200:
        description: Success message
        schema:
          id: success_message
          properties:
            status:
              type: number
              description: status code
              default: 200
            msg:
              type: string
              description: Status message
              default: 'Success'
      400:
          description: Error message
          schema:
            id: error_message
            properties:
              status:
                type: number
                description: status code
                default: 40000
              msg:
                type: string
                description: Status message
                default: 'Missing parameters'
    """
    content = request.get_json(force=True)
    if not all(param in content.keys() for param in ["name", "city", "owner", "description", "number_rooms", "number_bathrooms", "max_guest", "price_by_night", "latitude", "longitude"]):
        #ERROR
        return error_msg(400, 40000, "Missing parameters")
    try:
        place = Place()
        place.name = content["name"]
        place.city = content["city"]
        place.owner = content["owner"]
        place.description = content["description"]
        place.number_rooms = content["number_rooms"]
        place.number_bathrooms = content["number_bathrooms"]
        place.max_guest = content["max_guest"]
        place.price_by_night = content["price_by_night"]
        place.latitude = content["latitude"]
        place.longitude = content["longitude"]
        place.save()
    except Exception as e:
        return error_msg(400, 400, "Error")
    return error_msg(200, 200, "Success")
开发者ID:johnSerrano,项目名称:airbnb_clone,代码行数:98,代码来源:place.py

示例3: state_city_place

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import price_by_night [as 别名]
def state_city_place(state_id, city_id):
	if request.method == "GET":
		try:
			state_test = State.select().where(State.id == state_id)

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

			city_test = City.select().where(City.id == city_id)

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

			query = Place.select().where(Place.city == city_id)

			return ListStyle.list(query, request), 200

		except Place.DoesNotExist:
			return json_response(status_=404, code=404, msg="not found")

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

		try:
			city = City.get(City.id == city_id, City.state_id == state_id)

		except City.DoesNotExist:
			return json_response(status_=404, msg="City does not exist")

		try:
			place = Place(owner=request.form['owner_id'],
						city=city_id,
						name=request.form['name'])

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

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

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

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

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

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

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

			place.save()

		except IntegrityError:
			return json_response(status_=409, msg="Name already exists")

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

示例4: create_place_by_city

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import price_by_night [as 别名]
def create_place_by_city(state_id, city_id):
    """
    Create a new place
    Create a new place in the given city
    ---
    tags:
        - Place
    parameters:
        -
            name: state_id
            in: path
            type: integer
            required: True
            description: id of the state
        -
            name: city_id
            in: path
            type: integer
            required: True
            description: id of the city
        -
            name: owner_id
            in: form
            type: integer
            required: True
            description: user id of the owner
        -
            name: name
            in: form
            type: string
            required: True
            description: name of the place
        -
            name: description
            in: form
            type: string
            description: description of the place
        -
            name: number_rooms
            in: form
            type: integer
            description: number of rooms
        -
            name: number_bathrooms
            in: form
            type: integer
            description: number of bathrooms
        -
            name: max_guest
            in: form
            type: integer
            description: the max number of guests
        -
            name: price_by_night
            in: form
            type: integer
            description: the price per night of the location
        -
            name: latitude
            in: form
            type: float
            description: the latitude of the place location
        -
            name: longitude
            in: form
            type: float
            description: the longitude of the place location
    responses:
        201:
            description: Place was created
            schema:
                $ref: '#/definitions/create_amenity_post_post_success'
        400:
            description: Issue with place request
        404:
            description: Owner or city was not found
        500:
            description: The request was not able to be processed
    """
    try:
        data = {}
        for key in request.form.keys():
        	for value in request.form.getlist(key):
        		data[key] = value

        ''' Check for required keys '''
        if not 'owner_id' in data:
            raise KeyError('owner_id')
        if not 'name' in data:
            raise KeyError('name')

        ''' Check required key value data types '''
        if not type_test(data['owner_id'], int):
            raise TypeError('owner_id is not an integer')
        if not type_test(data['name'], 'string'):
            raise TypeError('name is not a string')

        ''' Check optional key value data types '''
        if 'description' in data and not type_test(data['description'], 'string'):
            raise TypeError('description is not a string')
#.........这里部分代码省略.........
开发者ID:rickharris-dev,项目名称:airbnb_clone,代码行数:103,代码来源:place.py


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