本文整理汇总了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)
示例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))