本文整理汇总了Python中app.models.amenity.Amenity.save方法的典型用法代码示例。如果您正苦于以下问题:Python Amenity.save方法的具体用法?Python Amenity.save怎么用?Python Amenity.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.amenity.Amenity
的用法示例。
在下文中一共展示了Amenity.save方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: amenities
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import save [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"
)
示例2: create_amenity
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import save [as 别名]
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
示例3: createAmenityViaPeewee
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import save [as 别名]
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
示例4: create_asdfstate
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import save [as 别名]
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"
示例5: create_amenity
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import save [as 别名]
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")
示例6: amenities
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import save [as 别名]
def amenities():
if request.method == 'GET':
amenities = Amenity.select()
return ListStyle.list(amenities, request), 200
elif request.method == 'POST':
try:
if "name" not in request.form:
return json_response(status_=400, msg="missing parameters", code=40000)
test = Amenity.select().where(Amenity.name == request.form["name"])
if test.wrapped_count() > 0:
return json_response(status_=409, code=10002, msg="place already exists with this name")
amenity = Amenity(name=request.form["name"])
amenity.save()
return jsonify(amenity.to_dict()), 201
except IntegrityError:
return json_response(status_=409,
msg="Name already exists",
code=10003)
示例7: test_Place_amenities
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity 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