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


Python amenity.Amenity類代碼示例

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


在下文中一共展示了Amenity類的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: create_amenity

def create_amenity():
    try:
        new_amenity = Amenity(name=request.form['name'])
        new_amenity.save()
        return jsonify(new_amenity.to_dict())
    except:
        return jsonify({'code': 10003, 'msg': 'Name already exists'}), 409
開發者ID:frakentoaster,項目名稱:airbnb_clone,代碼行數:7,代碼來源:amenity.py

示例3: amenities

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,代碼行數:28,代碼來源:amenity.py

示例4: 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

示例5: get_amenity

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,代碼行數:59,代碼來源:amenity.py

示例6: create_amenities

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,代碼行數:10,代碼來源:amenity.py

示例7: createAmenityViaPeewee

    def createAmenityViaPeewee(self):
        """
        Create an amenity record using the API's database/Peewee models.

        createAmenityViaPeewee returns the Peewee object for the record. This
        method will not work if the database models are not written correctly.
        """
        record = Amenity(name= 'amenity_name')
        record.save()
        return record
開發者ID:WilliamMcCann,項目名稱:airbnb_clone,代碼行數:10,代碼來源:amenity.py

示例8: amenities

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,代碼行數:11,代碼來源:amenity.py

示例9: delete_amenity

def delete_amenity(amenity_id):
    """
    Delete the given amenity
    Deletes 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 deleted successfully
            schema:
                id: delete_200
                required:
                    - code
                    - msg
                properties:
                    code:
                        type: integer
                        description: Response code from the API
                        default: 200
                    msg:
                        type: string
                        description: Message about record deletion
                        default: "deleted successfully"
        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')

        ''' Delete the amenity '''
        amenity = Amenity.delete().where(Amenity.id == amenity_id)
        amenity.execute()
        res = {}
        res['code'] = 200
        res['msg'] = "Amenity was deleted successfully"
        return res, 200
    except LookupError as e:
        abort(404)
    except Exception as e:
        abort(500)
開發者ID:rickharris-dev,項目名稱:airbnb_clone,代碼行數:53,代碼來源:amenity.py

示例10: create_asdfstate

def create_asdfstate():
    content = request.get_json()
    if not all(param in content.keys() for param in ["name"]):
        #ERROR
        return "Failed: bad input"
    try:
        amenity = Amenity()
        amenity.name = content["name"]
        amenity.save()
    except Exception as e:
        return "Failed"
    return "Success"
開發者ID:Praylin,項目名稱:airbnb_clone,代碼行數:12,代碼來源:amenity.py

示例11: create_amenity

def create_amenity():
    """
    Create an amenity
    Creates an amenity based on post parameters.
    ---
    tags:
      - amenity
    parameters:
      - name: name
        in: query
        type: string
        description: name of the amenity to create
    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 content: return error_msg(400, 400, "Error")
    if not all(param in content.keys() for param in ["name"]):
        #ERROR
        return error_msg(400, 40000, "Missing parameters")
    try:
        amenity = Amenity()
        amenity.name = content["name"]
        amenity.save()
    except Exception as e:
        return error_msg(400, 400, "Error")
    return error_msg(200, 200, "Success")
開發者ID:johnSerrano,項目名稱:airbnb_clone,代碼行數:52,代碼來源:amenities.py

示例12: get_place_amenities

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,代碼行數:33,代碼來源:amenity.py

示例13: amenity_id

def amenity_id(amenity_id):
    """Handle GET, PUT & DELETE requests to /amenities/<amenity_id> route.

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

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

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

    # handle PUT requests
    elif request.method == "DELETE":
        record.delete_instance()
        record.save()
        return 'deleted booking\n'
開發者ID:ronachong,項目名稱:airbnb_clone,代碼行數:31,代碼來源:amenity.py

示例14: delete_amenity

def delete_amenity(amenity_id):
    try:
        amenity = Amenity.get(Amenity.id == amenity_id)
        amenity.delete_instance()
        return jsonify({'msg': 'Deleted amenity!'})
    except:
        return jsonify({'code': 404, 'msg': 'not found'}), 404
開發者ID:frakentoaster,項目名稱:airbnb_clone,代碼行數:7,代碼來源:amenity.py

示例15: get_amenity

def get_amenity(id):
    try:
        amenity = Amenity.get(Amenity.id == id)
    except Exception:
        return {'code': 404, 'msg': 'Amenity not found'}, 404

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


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