本文整理汇总了Python中books.models.Book.query方法的典型用法代码示例。如果您正苦于以下问题:Python Book.query方法的具体用法?Python Book.query怎么用?Python Book.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类books.models.Book
的用法示例。
在下文中一共展示了Book.query方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: book_form
# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import query [as 别名]
def book_form(request, name):
book = Book.query(Book.name==name).get()
if request.method == 'POST':
form = BookForm(request.POST, instance=book)
if form.is_valid():
form.save()
return redirect('/books/')
else:
form = BookForm(instance=book)
return render(request, 'book_form.html', {'form': form})
示例2: view_library
# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import query [as 别名]
def view_library():
useraccount = flaskext.login.current_user
if not useraccount:
return jsonify({"Error":"User not signed in"})
books = {}
i = 0
for copy in useraccount.get_library():
book = Book.query(Book.key == copy.book).get()
books[i] = book.to_dict()
i += 1
return jsonify(JsonIterable.dict_of_dict(books))
示例3: get_my_book_list
# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import query [as 别名]
def get_my_book_list():
cur_user = current_user()
if not cur_user:
logging.info("there is not a user logged in")
return "<a href='%s' >Login</a>" %users.create_login_url(dest_url=url_for('manage_library'))
books = {}
counter = 0
for copy in cur_user.get_library():
book = Book.query(Book.key == copy.book).get()
books[counter] = book.to_dict()
counter += 1
return jsonify(JsonIterable.dict_of_dict(books))
示例4: discover
# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import query [as 别名]
def discover():
user = current_user()
booklist = []
string = ""
for connection in user.get_connections():
u = UserAccount.getuser(connection.id())
for copy in u.get_library():
book = Book.query(Book.key == copy.book).get()
booklist.append(book)
#Sort booklist alphabetically, with title as the primary sort key and author as secondary
booklist.sort(key=lambda book: book.author.lower())
booklist.sort(key=lambda book: book.title.lower())
return render_response('discover.html',books=booklist)
示例5: book_due_reminders
# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import query [as 别名]
def book_due_reminders():
count = 0
"""find all the books due tomorrow and send reminder emails"""
books = BookCopy.query(BookCopy.due_date==date.today() + timedelta(days=1)).fetch()
for book in books:
count += 1
owner = UserAccount.query(UserAccount.key==book.owner).get()
mail.send_mail(sender=owner.email,
to=UserAccount.query(UserAccount.key==book.borrower).get().email,
subject="Book Due Soon",
body="""Hey, remember that book you borrowed on Bookout from me, '%s'? Please get it back to me by tomorrow.
Thanks!
%s"""%(Book.query(Book.key==book.book).get().title,owner.name))
return "%s reminders were sent out" %count
示例6: library
# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import query [as 别名]
def library():
booklist = []
useraccount = current_user()
for copy in useraccount.get_library():
book = Book.query(Book.key == copy.book).get()
book.title = book.title
book.escapedtitle = re.escape(book.title)
if copy.borrower is None:
book.available = True
else:
book.available = False
booklist.append(book)
#Sort booklist alphabetically, with title as the primary sort key and author as secondary
booklist.sort(key=lambda book: book.author.lower())
booklist.sort(key=lambda book: book.title.lower())
return render_response('managelibrary.html', myBooks=booklist)
示例7: profile
# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import query [as 别名]
def profile(userID):
profile_user = UserAccount.get_by_id(int(userID))
user = current_user()
if not profile_user:
return render_response('invalidprofile.html')
if user.is_connected(profile_user):
library = []
for copy in profile_user.get_library():
book = Book.query(Book.key == copy.book).get()
library.append(book)
if copy.borrower is None:
book.available = True
else:
book.available = False
book.copyid = copy.key.id()
return render_response('profile.html',profile_user=profile_user,library=library)
return render_response('invalidprofile.html')
示例8: books
# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import query [as 别名]
def books(request):
return render(request, 'books.html', {'books': Book.query()})