本文整理汇总了Python中app.models.amenity.Amenity.get方法的典型用法代码示例。如果您正苦于以下问题:Python Amenity.get方法的具体用法?Python Amenity.get怎么用?Python Amenity.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.amenity.Amenity
的用法示例。
在下文中一共展示了Amenity.get方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: subtest_createWithAllParams
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import get [as 别名]
def subtest_createWithAllParams(self):
"""
Test proper creation of an amenity record upon POST request to the API
with all parameters provided.
"""
POST_request1 = self.createAmenityViaAPI()
self.assertEqual(POST_request1.status[:3], '200')
now = datetime.now().strftime('%d/%m/%Y %H:%M')
self.assertEqual(Amenity.get(Amenity.id == 1).name, 'amenity_name')
self.assertEqual(Amenity.get(Amenity.id == 1).created_at.strftime('%d/%m/%Y %H:%M'), now)
self.assertEqual(Amenity.get(Amenity.id == 1).updated_at.strftime('%d/%m/%Y %H:%M'), now)
# test that placebook ID for sole record in database is correct
self.assertEqual(Amenity.select().get().id, 1)
示例2: get_amenity
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import get [as 别名]
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
示例3: amenity_id
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import get [as 别名]
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'
示例4: delete_amenity
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import get [as 别名]
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
示例5: get_amenity
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import get [as 别名]
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)
示例6: delete_amenity
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import get [as 别名]
def delete_amenity(id):
try:
amenity = Amenity.get(Amenity.id == id)
except Exception:
return {'code': 404, 'msg': 'Amenity not found'}, 404
amenity.delete_instance()
return {'code': 200, 'msg': 'Deleted successfully'}, 200
示例7: del_amenity
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import get [as 别名]
def del_amenity(amenity_id):
try:
query = Amenity.get(Amenity.id == amenity_id)
except Amenity.DoesNotExist:
return {"code":404, "msg": "not found"}, 404
out_dict = query.to_dict()
query.delete_instance()
return out_dict
示例8: update
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import get [as 别名]
def update(place_id, amenity_id):
# Checking if place exist
try:
Place.get(Place.id == place_id)
except Place.DoesNotExist:
return jsonify({'code': 404, 'msg': 'Place not found'}), 404
# Checking is Amenity exist
try:
Amenity.get(Amenity.id == amenity_id)
except Amenity.DoesNotExist:
return jsonify({'code': 404, 'msg': 'Amenity not found'}), 404
if request.method == "POST":
new_place_amenity = PlaceAmenities(place=place_id, amenity=amenity_id)
new_place_amenity.save()
return jsonify(new_place_amenity.amenity.to_dict())
elif request.method == "DELETE":
get_place_a = PlaceAmenities.get(PlaceAmenities.place == place_id and
PlaceAmenities.amenity == amenity_id)
get_place_a.delete_instance
return "amenity deleted"
示例9: amenities_id
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import get [as 别名]
def amenities_id(amenity_id):
if request.method == 'GET':
try:
amenity = Amenity.select().where(Amenity.id == amenity_id)
except Amenity.DoesNotExist:
return json_response(status_=404, msg="Not found")
return jsonify(amenity.to_dict()), 200
elif request.method == 'DELETE':
try:
amenity = Amenity.get(Amenity.id == amenity_id)
except Amenity.DoesNotExist:
return json_response(status_=404, msg="Not found")
amenity.delete_instance()
amenity.save()
return json_response(status_=200, msg="Amenity deleted")
示例10: find_amenity
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import get [as 别名]
def find_amenity(amenity_id):
try:
list = Amenity.get(Amenity.id == amenity_id)
return jsonify(list.to_dict())
except:
return jsonify({'code': 404, 'msg': 'not found'}), 404
示例11: get_amenity_by_id
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import get [as 别名]
def get_amenity_by_id(amenity_id):
try:
get_amenity = Amenity.get(Amenity.id == amenity_id)
except Amenity.DoesNotExist:
return {"code":404, "msg": "not found"}, 404
return get_amenity.to_dict()