當前位置: 首頁>>代碼示例>>Python>>正文


Python Amenity.select方法代碼示例

本文整理匯總了Python中app.models.amenity.Amenity.select方法的典型用法代碼示例。如果您正苦於以下問題:Python Amenity.select方法的具體用法?Python Amenity.select怎麽用?Python Amenity.select使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app.models.amenity.Amenity的用法示例。


在下文中一共展示了Amenity.select方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: handle_amenity_for_place

# 需要導入模塊: from app.models.amenity import Amenity [as 別名]
# 或者: from app.models.amenity.Amenity 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: get_amenities

# 需要導入模塊: from app.models.amenity import Amenity [as 別名]
# 或者: from app.models.amenity.Amenity import select [as 別名]
def get_amenities():
    amenities = []
    query = Amenity.select()
    for i in query:
        amenities.append(i.to_hash())

    return jsonify(amenities)
開發者ID:havk64,項目名稱:airbnb_clone,代碼行數:9,代碼來源:amenity.py

示例3: place_amenity_id

# 需要導入模塊: from app.models.amenity import Amenity [as 別名]
# 或者: from app.models.amenity.Amenity 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

示例4: get_amenity_by_place

# 需要導入模塊: from app.models.amenity import Amenity [as 別名]
# 或者: from app.models.amenity.Amenity import select [as 別名]
def get_amenity_by_place(id):
    amenities = []
    query = Amenity.select().where(Place.id == id)
    for i in query:
        amenities.append(i.to_hash())

    return jsonify(amenities)
開發者ID:havk64,項目名稱:airbnb_clone,代碼行數:9,代碼來源:amenity.py

示例5: amenities

# 需要導入模塊: from app.models.amenity import Amenity [as 別名]
# 或者: from app.models.amenity.Amenity import select [as 別名]
def amenities():
    """Handle GET and POST requests to /amenities route.

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

    # handle POST requests:
    # --------------------------------------------------------------------------
    elif request.method == 'POST':
        try:
            record = Amenity(name=request.form['name'])
            record.save()
            return jsonify(record.to_hash())

        # return 409 if amenity with given name already exists
        except IntegrityError:
                return json_response(
                    add_status_=False,
                    status_=409,
                    code=10003,
                    msg="Name already exists"
                )
開發者ID:ronachong,項目名稱:airbnb_clone,代碼行數:30,代碼來源:amenity.py

示例6: get_place_amenities

# 需要導入模塊: from app.models.amenity import Amenity [as 別名]
# 或者: from app.models.amenity.Amenity 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

示例7: get_amenity

# 需要導入模塊: from app.models.amenity import Amenity [as 別名]
# 或者: from app.models.amenity.Amenity import select [as 別名]
def get_amenity(amenity_id):
    """
    Get the given amenity
    Return the given amenity in the database.
    ---
    tags:
        - Amenity
    parameters:
        -
            in: path
            name: amenity_id
            type: string
            required: True
            description: ID of the amenity
    responses:
        200:
            description: Amenity returned successfully
            schema:
                id: Amenity
                required:
                    - name
                    - id
                    - created_at
                    - updated_at
                properties:
                    name:
                        type: string
                        description: Name of the amenity
                        default: "Swimming Pool"
                    id:
                        type: number
                        description: id of the amenity
                        default: 1
                    created_at:
                        type: datetime string
                        description: date and time the amenity was created in the database
                        default: '2016-08-11 20:30:38'
                    updated_at:
                        type: datetime string
                        description: date and time the amenity was updated in the database
                        default: '2016-08-11 20:30:38'
        404:
            description: Amenity was not found
        500:
            description: Request could not be processed
    """
    try:
        ''' Check if amenity exists '''
        query = Amenity.select().where(Amenity.id == amenity_id)
        if not query.exists():
            raise LookupError('amenity_id')

        ''' Return amenity data '''
        amenity = Amenity.get(Amenity.id == amenity_id)
        return amenity.to_dict(), 200
    except LookupError as e:
        abort(404)
    except Exception as e:
        abort(500)
開發者ID:rickharris-dev,項目名稱:airbnb_clone,代碼行數:61,代碼來源:amenity.py

示例8: amenities_place

# 需要導入模塊: from app.models.amenity import Amenity [as 別名]
# 或者: from app.models.amenity.Amenity import select [as 別名]
def amenities_place(place_id):
	if request.method == "GET":
		try:
			query = Amenity.select().join(PlaceAmenities).where(PlaceAmenities.place == place_id)
			return ListStyle.list(query, request), 200

		except:
			return json_response(status_=404, msg="Not found")
開發者ID:jdeepee,項目名稱:airbnb_clone,代碼行數:10,代碼來源:amenity.py

示例9: amenities_id

# 需要導入模塊: from app.models.amenity import Amenity [as 別名]
# 或者: from app.models.amenity.Amenity import select [as 別名]
def amenities_id(amenity_id):

	amenity = Amenity.select().where(id=amenity_id).get()
	if request.method == 'GET':
		return amenity.to_hash()

	elif request.method == 'DELETE':
		amenity.delete_instance()
開發者ID:DoraKorpar,項目名稱:airbnb_clone,代碼行數:10,代碼來源:amenity.py

示例10: get_statdasfde_by_id

# 需要導入模塊: from app.models.amenity import Amenity [as 別名]
# 或者: from app.models.amenity.Amenity import select [as 別名]
def get_statdasfde_by_id(amen_id):
    amens = Amenity.select().where(Amenity.id == int(amen_id))
    amen = None
    for u in amens:
        amen = u
    if amen == None:
        return "Failed"
    return jsonify(amen.to_hash())
開發者ID:Praylin,項目名稱:airbnb_clone,代碼行數:10,代碼來源:amenity.py

示例11: get_staasedfazte_by_id

# 需要導入模塊: from app.models.amenity import Amenity [as 別名]
# 或者: from app.models.amenity.Amenity import select [as 別名]
def get_staasedfazte_by_id(amen_id):
    amens = Amenity.select().where(Amenity.id == int(amen_id))
    amen = None
    for u in amens:
        amen = u
    if amen == None:
        return "Failed"
    amen.delete_instance()
    return "Success"
開發者ID:Praylin,項目名稱:airbnb_clone,代碼行數:11,代碼來源:amenity.py

示例12: create_amenities

# 需要導入模塊: from app.models.amenity import Amenity [as 別名]
# 或者: from app.models.amenity.Amenity import select [as 別名]
def create_amenities():
    data = request.form
    check_amenity =  Amenity.select(). where(Amenity.name == data['name'])
    if check_amenity:
        return {'code': 10003, 'msg': 'Name already exists'}, 409

    amenity = Amenity.create(
        name = data['name']
    )
    return {'code': 201, 'msg': 'Amenity created successfully'}, 201
開發者ID:havk64,項目名稱:airbnb_clone,代碼行數:12,代碼來源:amenity.py

示例13: handle_amenity

# 需要導入模塊: from app.models.amenity import Amenity [as 別名]
# 或者: from app.models.amenity.Amenity import select [as 別名]
def handle_amenity():
    '''Returns all amenities as JSON objects in an array with a GET request.
    Adds an amenity with a POST request.
    '''
    if request.method == 'GET':
        list = ListStyle().list(Amenity.select(), request)
        return jsonify(list), 200

    elif request.method == 'POST':
        try:
            Amenity.select().where(Amenity.name == request.form['name']).get()
            return jsonify(code=10003, msg="Name already exists"), 409
        except Amenity.DoesNotExist:
            '''Check that all the required parameters are made in request.'''
            required = set(["name"]) <= set(request.values.keys())
            if required is False:
                return jsonify(msg="Missing parameter."), 400

            amenity = Amenity.create(name=request.form['name'])
            return jsonify(amenity.to_dict()), 200
開發者ID:Siphan,項目名稱:airbnb_clone,代碼行數:22,代碼來源:amenity.py

示例14: amenities

# 需要導入模塊: from app.models.amenity import Amenity [as 別名]
# 或者: from app.models.amenity.Amenity import select [as 別名]
def amenities():
	if request.method == 'GET':
		list_amenities = Amenity.select()
		return json_dumps(list_amenities.to_hash())

	elif request.method == 'POST':
		data = request.data
		name = data['name']

		entry = Amenity.insert(name=name)
		entry.execute()
開發者ID:DoraKorpar,項目名稱:airbnb_clone,代碼行數:13,代碼來源:amenity.py

示例15: list_select_amenities

# 需要導入模塊: from app.models.amenity import Amenity [as 別名]
# 或者: from app.models.amenity.Amenity import select [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


注:本文中的app.models.amenity.Amenity.select方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。