本文整理汇总了Python中app.models.amenity.Amenity.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Amenity.delete方法的具体用法?Python Amenity.delete怎么用?Python Amenity.delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.amenity.Amenity
的用法示例。
在下文中一共展示了Amenity.delete方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_amenity_for_place
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import delete [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
示例2: delete_amenity
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import delete [as 别名]
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)
示例3: handle_amenity_id
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import delete [as 别名]
def handle_amenity_id(amenity_id):
'''Returns a JSON object of the amenity with the id passed as parameter
with a GET request method. Removes an amenity with DELETE request method.
Keyword arguments:
amenity_id: The id of the amenity.
'''
try:
amenity = Amenity.select().where(Amenity.id == amenity_id).get()
except Amenity.DoesNotExist:
raise Exception("There is no amenity with this id.")
if request.method == 'GET':
return jsonify(amenity.to_dict()), 200
elif request.method == 'DELETE':
amenity = Amenity.delete().where(Amenity.id == amenity_id)
amenity.execute()
return jsonify(msg="Amenity deleted successfully."), 200
示例4: setUp
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import delete [as 别名]
def setUp(self):
#connect to db and delete everyone in the amenities table
Amenity.delete().execute()
示例5: tearDown
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import delete [as 别名]
def tearDown(self):
#delete all from amenities
Amenity.delete().execute()