当前位置: 首页>>代码示例>>Python>>正文


Python Book.get_by_isbn方法代码示例

本文整理汇总了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"})
开发者ID:byu-osl,项目名称:bookout,代码行数:41,代码来源:api.py

示例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()))
开发者ID:byu-osl,项目名称:bookout,代码行数:8,代码来源:api.py


注:本文中的books.models.Book.get_by_isbn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。