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


Python Place.save方法代码示例

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


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

示例1: test_review_place2

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import save [as 别名]
    def test_review_place2(self):
        # Creating a setUp
        new_state = State(name='California')
        new_state.save()
        new_city = City(name='San Francisco', state=1)
        new_city.save()
        new_place = Place(owner=1,
                          city=1,
                          name="Steven",
                          description="house",
                          number_rooms=3,
                          number_bathrooms=2,
                          max_guest=3,
                          price_by_night=100,
                          latitude=37.774929,
                          longitude=-122.419416)
        new_place.save()

        # Creating a review for a place that exist
        new_review = self.app.post('/places/1/reviews',
                                   data=dict(message="I like it",
                                             stars=5))
        assert new_review.status_code == 200
        # checking the review id, should be 1
        assert json.loads(new_review.data)["id"] == 1
        # Creating a review for a place that does not exist
        new_review = self.app.post('/places/3/reviews',
                                   data=dict(message="I like it",
                                             user_id=1,
                                             stars=5))
        assert new_review.status_code == 404
开发者ID:frakentoaster,项目名称:airbnb_clone,代码行数:33,代码来源:review.py

示例2: test_review_place3

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import save [as 别名]
    def test_review_place3(self):
        # Creating a setUp
        new_state = State(name='California')
        new_state.save()
        new_city = City(name='San Francisco', state=1)
        new_city.save()
        new_place = Place(owner=1,
                          city=1,
                          name="Steven",
                          description="house",
                          number_rooms=3,
                          number_bathrooms=2,
                          max_guest=3,
                          price_by_night=100,
                          latitude=37.774929,
                          longitude=-122.419416)
        new_place.save()

        # Creating a review for a place that exist
        new_review = self.app.post('/places/1/reviews',
                                   data=dict(message="I like it",
                                             stars=5))
        assert new_review.status_code == 200

        # Checking for a review that does not exist
        new_review_get = self.app.get('/places/1/reviews/5')
        assert new_review_get.status_code == 404

        # Checking for a place that does not exist
        new_review_get = self.app.get('/places/2/reviews/2')
        assert new_review_get.status_code == 404

        # Checking for a review that does exist
        new_review_get = self.app.get('/places/1/reviews/1')
        assert new_review_get.status_code == 200
开发者ID:frakentoaster,项目名称:airbnb_clone,代码行数:37,代码来源:review.py

示例3: places

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

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import save [as 别名]
    def setUp(self):
        # disabling logs
        logging.disable(logging.CRITICAL)
        self.app = app.test_client()
        # connecting to the database
        db.connect()
        # creating tables
        db.create_tables([User], safe=True)
        db.create_tables([State], safe=True)
        db.create_tables([City], safe=True)
        db.create_tables([Place], safe=True)
        db.create_tables([PlaceBook], safe=True)

        # Creating a setUp
        new_state = State(name='California')
        new_state.save()
        new_city = City(name='San Francisco', state=1)
        new_city.save()
        # Creating a new users
        user1 = User(first_name='Jon',
                     last_name='Snow',
                     email='[email protected]',
                     password='toto1234')
        user1.save()
        new_place = Place(owner=1,
                          city=1,
                          name="Steven",
                          description="house",
                          number_rooms=3,
                          number_bathrooms=2,
                          max_guest=3,
                          price_by_night=100,
                          latitude=37.774929,
                          longitude=-122.419416)
        new_place.save()
开发者ID:frakentoaster,项目名称:airbnb_clone,代码行数:37,代码来源:place_book.py

示例5: setUp

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import save [as 别名]
    def setUp(self):
        """
        Overload def setUp(self): to create a test client of airbnb app, and
        create placebook table in airbnb_test database.
        """
        self.app = app.test_client()        # set up test client
        self.app.testing = True             # set testing to True
        logging.disable(logging.CRITICAL)   # disable logs

        # connect to airbnb_test database and create tables
        database.connect()
        database.create_tables([User, State, City, Place, PlaceBook], safe=True)

        # create user record for route
        user_record = User( email='anystring',
                            password='anystring1',
                            first_name='anystring2',
                            last_name='anystring3'  )
        user_record.save()

        # create state record for route
        state_record = State(name="foo-state")
        state_record.save()

        # create city record for route
        city_record = City(name="foo-city", state="1")
        city_record.save()

        # create place records for route
        place_record = Place(   owner=1,
                                city=1,
                                name="foo",
                                description="foo description",
                                number_rooms=1,
                                number_bathrooms=1,
                                max_guest=1,
                                price_by_night=1,
                                latitude=20.0,
                                longitude=22.0    )
        place_record.save()

        place_record2 = Place(  owner=1,
                                city=1,
                                name="foo",
                                description="foo description",
                                number_rooms=1,
                                number_bathrooms=1,
                                max_guest=1,
                                price_by_night=1,
                                latitude=20.0,
                                longitude=22.0    )
        place_record2.save()
开发者ID:WilliamMcCann,项目名称:airbnb_clone,代码行数:54,代码来源:place_book.py

示例6: places

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

示例7: createPlaceViaPeewee

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import save [as 别名]
    def createPlaceViaPeewee(self):
        """
        Create a place record using the API's database/Peewee models.

        createPlaceViaPeewee returns the Peewee object for the record. This
        method will not work if the database models are not written correctly.
        """
        record = Place( owner_id=1,
                        city_id=1,
                        name="foo",
                        description="foo description",
                        number_rooms=1,
                        number_bathrooms=1,
                        max_guest=1,
                        price_by_night=1,
                        latitude=20.0,
                        longitude=22.0 )
        record.save()
        return record
开发者ID:WilliamMcCann,项目名称:airbnb_clone,代码行数:21,代码来源:place.py

示例8: test_delete2

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import save [as 别名]
    def test_delete2(self):
        # Creating a setUp
        new_state = State(name='California')
        new_state.save()
        new_city = City(name='San Francisco', state=1)
        new_city.save()
        new_place = Place(owner=1,
                          city=1,
                          name="Steven",
                          description="house",
                          number_rooms=3,
                          number_bathrooms=2,
                          max_guest=3,
                          price_by_night=100,
                          latitude=37.774929,
                          longitude=-122.419416)
        new_place.save()

        # creating a review by an user that exist
        new_review = self.app.post('/places/1/reviews',
                                   data=dict(message="I like it",
                                             stars=5))
        assert new_review.status_code == 200

        # checking how many reviews there are before deleting
        get_review = self.app.get('/places/1/reviews/1')
        assert get_review.status_code == 200

        # delition of a review that does not exist
        deleting_review = self.app.delete('/places/1/reviews/3')
        assert deleting_review.status_code == 404

        # delition of a review that does not exist
        deleting_review = self.app.delete('/places/13/reviews/1')
        assert deleting_review.status_code == 404

        # delition of a review that does not exist
        deleting_review = self.app.delete('/places/1/reviews/1')
        assert deleting_review.status_code == 200

        # checking how many reviews there are after deleting
        get_review = self.app.get('/places/1/reviews/1')
        assert get_review.status_code == 404
开发者ID:frakentoaster,项目名称:airbnb_clone,代码行数:45,代码来源:review.py

示例9: list_of_place

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

    if request.method == 'POST':
        new_place = Place(owner=request.form['owner'],
                          city=request.form['city'],
                          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']
                          )
        new_place.save()
        return "place created"
开发者ID:frakentoaster,项目名称:airbnb_clone,代码行数:22,代码来源:place.py

示例10: city_places

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import save [as 别名]
def city_places(state_id, city_id):
    """Handle GET & POST requests to /states/<state_id>/cities/<city_id>/places.

    Return a list of all places in the database in given city in the case of a
    GET request.
    Create a new place record in the given city in the database in the case of
    a POST request.
    """
    # handle GET requests:
    # --------------------------------------------------------------------------
    if request.method == 'GET':
        try:
            list = ListStyle.list(Place.select().where(Place.city == city_id), request)
            return jsonify(list)

        # return 404 not found record does not exist
        except Place.DoesNotExist:
            return json_response(
                add_status_=False,
                status_=404,
                code=404,
                msg="not found"
            )

    # handle POST requests:
    # --------------------------------------------------------------------------
    elif request.method == 'POST':
        record = Place( owner=request.form['owner_id'],
                        city=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,代码行数:41,代码来源:place.py

示例11: test_Place_amenities

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import save [as 别名]
    def test_Place_amenities(self):
        new_state = State(name='California')
        new_state.save()
        new_city = City(name='San Francisco', state=1)
        new_city.save()
        # Creating a new users
        user1 = User(first_name='Jon',
                     last_name='Snow',
                     email='[email protected]',
                     password='toto1234')
        user1.save()
        # Creating Place
        new_place = Place(owner=1,
                          city=1,
                          name="Steven",
                          description="house",
                          number_rooms=3,
                          number_bathrooms=2,
                          max_guest=3,
                          price_by_night=100,
                          latitude=37.774929,
                          longitude=-122.419416)
        new_place.save()
        # Creating an amenity
        new_amenity = Amenity(name="amenity1")
        new_amenity.save()

        # Creating a place amenity

        new_place_amenity = PlaceAmenities(place=1, amenity=1)
        new_place_amenity.save()

        # Creating amenity test for different user
        new_state = State(name='Oregon')
        new_state.save()
        new_city = City(name='San Francisco', state=1)
        new_city.save()

        # Creating a new users 2
        user1 = User(first_name='Jon',
                     last_name='Snow',
                     email='[email protected]',
                     password='toto1234')
        user1.save()

        # Creating Place 2
        new_place = Place(owner=2,
                          city=2,
                          name="Steven",
                          description="house",
                          number_rooms=3,
                          number_bathrooms=2,
                          max_guest=3,
                          price_by_night=100,
                          latitude=37.774929,
                          longitude=-122.419416)
        new_place.save()
        # Creating an amenity 2
        new_amenity = Amenity(name="amenity2")
        new_amenity.save()

        # Creating a place amenity 1
        new_place_amenity = PlaceAmenities(place=1, amenity=2)
        new_place_amenity.save()

        # Creating a place amenity 2
        new_place_amenity = PlaceAmenities(place=2, amenity=2)
        new_place_amenity.save()

        # testing amenities for a different place
        get_place_amenity = self.app.get('/places/1/amenities')
        # assert get_place_amenity.status_code == 200
        print get_place_amenity.data

        # testing amenities for a different place
        get_place_amenity = self.app.get('/places/2/amenities')
        assert get_place_amenity.status_code == 200

        # testing amenities for a different place that does not exist
        get_place_amenity = self.app.get('/places/3/amenities')
        assert get_place_amenity.status_code == 404

        # creating a new amenity to a place
        add_amenity = self.app.post('/places/1/amenities/1')
        assert add_amenity.status_code == 200

        # creating a new amenity to a place that does not exist
        add_amenity = self.app.post('/places/3/amenities/1')
        assert add_amenity.status_code == 404

        # creating a new amenity that does not exist for a place
        add_amenity = self.app.post('/places/1/amenities/3')
        assert add_amenity.status_code == 404

        # deleting amenities from a place
        delete_amenity = self.app.delete('/places/1/amenities/1')
        assert delete_amenity.status_code == 200
开发者ID:frakentoaster,项目名称:airbnb_clone,代码行数:99,代码来源:amenity.py

示例12: create_places

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

示例13: state_city_place

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

示例14: create_place_by_city

# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import save [as 别名]

#.........这里部分代码省略.........
        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')
        if 'number_rooms' in data and not type_test(data['number_rooms'], int):
            raise TypeError('number_rooms is not an integer')
        if 'number_bathrooms' in data and not type_test(data['number_bathrooms'], int):
            raise TypeError('number_bathrooms is not an integer')
        if 'max_guest' in data and not type_test(data['max_guest'], int):
            raise TypeError('max_guest is not an integer')
        if 'price_by_night' in data and not type_test(data['price_by_night'], int):
            raise TypeError('price_by_night is not an integer')
        if 'latitude' in data and not type_test(data['latitude'], float):
            raise TypeError('latitude is not a float')
        if 'longitude' in data and not type_test(data['longitude'], float):
            raise TypeError('longitude is not a float')

        ''' Check if the state_id exists '''
        query = State.select().where(State.id == state_id)
        if not query.exists():
            raise LookupError('state_id')

        ''' Check if the city_id exists '''
        query = City.select().where(City.id == city_id)
        if not query.exists():
            raise LookupError('city_id')

        ''' Check if the city_id is associated to the state_id '''
        city = City.get(City.id == city_id)
        query = State.select().where(State.id == city.state, State.id == state_id)
        if not query.exists():
            raise LookupError('city_id, state_id')

        ''' Check if the owner_id exists '''
        query = User.select().where(User.id == data['owner_id'])
        if not query.exists():
            raise LookupError('owner_id')

        new = Place(
            owner = data['owner_id'],
            name = data['name'],
            city = city.id
        )
        if data['description']:
            new.description = data['description']
        if data['number_rooms']:
            new.number_rooms = data['number_rooms']
        if data['number_bathrooms']:
            new.number_bathrooms = data['number_bathrooms']
        if data['max_guest']:
            new.max_guest = data['max_guest']
        if data['price_by_night']:
            new.price_by_night = data['price_by_night']
        if data['latitude']:
            new.latitude = data['latitude']
        if data['longitude']:
            new.longitude = data['longitude']
        new.save()
        res = {}
        res['code'] = 201
        res['id'] = new.id
        res['msg'] = "Place was created successfully"
        return res, 201
    except KeyError as e:
        res = {}
        res['code'] = 40000
        res['msg'] = 'Missing parameters'
        return res, 400
    except LookupError as e:
        abort(404)
    except TypeError as e:
        res = {}
        res['code'] = 400
        res['msg'] = e.message
        return res, 400
    except Exception as e:
        print e.message
        abort(500)
开发者ID:rickharris-dev,项目名称:airbnb_clone,代码行数:104,代码来源:place.py


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