本文整理匯總了Python中models.Ticket.book_temp方法的典型用法代碼示例。如果您正苦於以下問題:Python Ticket.book_temp方法的具體用法?Python Ticket.book_temp怎麽用?Python Ticket.book_temp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Ticket
的用法示例。
在下文中一共展示了Ticket.book_temp方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: book_ticket
# 需要導入模塊: from models import Ticket [as 別名]
# 或者: from models.Ticket import book_temp [as 別名]
def book_ticket():
if 'user_id' not in session:
return login_in_please()
user_id = session['user_id']
req = request.get_json()
if 'type' not in req:
return bad_request()
ticket_type = req['type']
if ticket_type not in app.config['TYPE_IDS'].values():
return bad_request()
seat_num = None
if ticket_type == app.config['TYPE_IDS']['pc']:
if 'seat' not in req:
return bad_request()
seat_num = req['seat']
tickets_max = app.config['TICKETS_MAX']
price = app.config['PRICING'][ticket_type]
r = Ticket.book_temp(user_id, ticket_type, price, tickets_max, seat_num)
if r[0]:
ticket = Ticket.query.filter(Ticket.owner_id == user_id) \
.filter(or_(Ticket.paid, Ticket.reserved_until >= datetime.now())) \
.one()
return jsonify({'ticket': ticket.as_pub_dict()}), 201
# Conflict while booking ticket
return jsonify({'error': str(r[1])}), 409