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


Python Book.search_books_by_attribute方法代码示例

本文整理汇总了Python中books.models.Book.search_books_by_attribute方法的典型用法代码示例。如果您正苦于以下问题:Python Book.search_books_by_attribute方法的具体用法?Python Book.search_books_by_attribute怎么用?Python Book.search_books_by_attribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在books.models.Book的用法示例。


在下文中一共展示了Book.search_books_by_attribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: searchbooks

# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import search_books_by_attribute [as 别名]
def searchbooks():
	booklist = {}
	searchterm = request.args.get('value')
	attr = request.args.get('refineSearch')
	
	if attr == "all":
		attr = None
	
	if searchterm is None:
		searchterm = ""
	else:
		searchterm = searchterm.lstrip()
		
	if searchterm is None or searchterm == "":
		pass
	else:
		cur_user = current_user()
		logging.info(cur_user)
		if not cur_user.is_authenticated():
			#Assume no books in library or network, return results only
			booklist = Book.search_books_by_attribute(searchterm,attr)
			for book in booklist:
				booklist[book] = booklist[book].to_dict()
				#Assume not in booklist or networkbooklist
				booklist[book]["inLibrary"] = "False"
				booklist[book]["inNetwork"] = "False"
		
		else:
			user = current_user()
			
			#Create a dictionary of the user's books
			mybooklist = {}
			for copy in user.get_library():
				mybooklist[copy.OLKey] = copy
				
			#Create a dictionary of the books in my network
			networkbooklist = {}
			string = ""
			for connection in user.get_connections():
				u = UserAccount.getuser(connection.id())
				for copy in u.get_library():
					networkbooklist[copy.OLKey] = copy

			booklist = Book.search_books_by_attribute(searchterm,attr)
			for book in booklist:
				booklist[book] = booklist[book].to_dict()
				booklist[book]["escapedtitle"] = re.escape(booklist[book]["title"])
				if booklist[book]['OLKey'] in mybooklist:
					booklist[book]["inLibrary"] = "True"
				else:
					booklist[book]["inLibrary"] = "False"
					
				if booklist[book]['OLKey'] in networkbooklist:
					booklist[book]["inNetwork"] = "True"
				else:
					booklist[book]["inNetwork"] = "False"
				
	return render_response('searchbooks.html', books=booklist, search=searchterm, attribute=attr)
开发者ID:byu-osl,项目名称:bookout,代码行数:60,代码来源:views.py

示例2: search_for_book

# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import search_books_by_attribute [as 别名]
def search_for_book(value, attribute=None):
	books = Book.search_books_by_attribute(value,attribute)
	if len(books) == 0:
		return jsonify({"Message":"No books found"})
	else:
		return jsonify(JsonIterable.dict_of_dict(books))
开发者ID:byu-osl,项目名称:bookout,代码行数:8,代码来源:views.py


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