本文整理汇总了Python中books.models.Book.get_by_isbn方法的典型用法代码示例。如果您正苦于以下问题:Python Book.get_by_isbn方法的具体用法?Python Book.get_by_isbn怎么用?Python Book.get_by_isbn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类books.models.Book
的用法示例。
在下文中一共展示了Book.get_by_isbn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: library_book
# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import get_by_isbn [as 别名]
def library_book(ISBN):
useraccount = flaskext.login.current_user
if not useraccount:
return jsonify({"Error":"User not signed in"})
if request.method == 'GET':
#check the database to see if the book is in the user's library
book = Book.get_by_isbn(ISBN)
if book:
if useraccount.get_book(book):
return jsonify(JsonIterable.dictionary(book.to_dict()))
else:
return jsonify({"Message":"This book is not in your library"})
else:
return jsonify({"Message":"Book not found"})
elif request.method == 'POST':
#add the book to the user's library
#If not found, add it to the cache, then to the user's library
book = Book.get_by_isbn(ISBN)
if not book:
return jsonify({"Message":"Book not found"})
else:
if useraccount.get_book(book):
return jsonify({"Message":"This book is already in your library"})
useraccount.add_book(book)
return jsonify({"Message":"Book " + ISBN + " was added to your library"})
elif request.method == 'DELETE':
#remove the book from the user's library
book = Book.get_by_isbn(ISBN)
if not book:
return jsonify({"Message":"Book not found"})
else:
if useraccount.get_book(book):
useraccount.remove_book(book)
return jsonify({"Message":"Successfully deleted " + ISBN + " from your library"})
else:
#this should never be reached
return jsonify({"Error":"Invalid http request"})
示例2: get_book
# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import get_by_isbn [as 别名]
def get_book(ISBN):
book = Book.get_by_isbn(ISBN)
if not book:
return jsonify({"Message":"Book not found"})
else:
return jsonify(JsonIterable.dictionary(book.to_dict()))