当前位置: 首页>>代码示例>>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;未经允许,请勿转载。