本文整理汇总了Python中models.Book.query方法的典型用法代码示例。如果您正苦于以下问题:Python Book.query方法的具体用法?Python Book.query怎么用?Python Book.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Book
的用法示例。
在下文中一共展示了Book.query方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: queryCheckouts
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import query [as 别名]
def queryCheckouts(self, request):
"""get checkout records"""
self._ensureAdmin()
q = Book.query(Book.checkedOut == True)
if request.overDue == True:
q = q.filter(Book.dueDate<date.today())
elif request.sbId:
q = q.filter( ndb.AND(
Book.sbId >= request.sbId.upper(),
Book.sbId < request.sbId.upper() + 'Z' ))
q = q.order(Book.sbId)
elif request.name:
q = q.filter( ndb.AND(
Book.title >= request.name.lower(),
Book.title < request.name.lower() + 'z'))
q = q.order(Book.title)
curs = Cursor(urlsafe=request.cursor)
books, nextcurs, more = q.fetch_page(PAGE_SIZE, start_cursor=curs)
nextcursor = None
if more and nextcurs:
nextcursor = nextcurs.urlsafe()
return CheckoutForms(items = [self._copyCheckoutToForm(checkout) \
for checkout in books], cursor = nextcursor)
示例2: get
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import query [as 别名]
def get(self):
# Get all the displayable books
books_query = Book.query(ancestor=ROOT_BOOK_KEY)
# Get the books currently in the cart
cart_query = []
# check for a person and filter the books
if self.person:
books_query = books_query.filter(ndb.OR(Book.cart_key == None, Book.cart_key == self.person.key))
cart_query = self.person.get_cart()
else:
# remove all the books that are in someone's cart
books_query = books_query.filter(Book.cart_key == None)
books_query = books_query.order(-Book.last_touch_date_time)
# Get additional details needed to populate lists
dept_query = Department.query(ancestor=ROOT_DEPT_KEY).order(Department.abbrev)
book_conditions = Book.get_conditions()
self.values.update({"books_query": books_query,
"cart_query" : cart_query,
"dept_query": dept_query,
"book_conditions": book_conditions})
self.render(**self.values)
示例3: queryBooks
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import query [as 别名]
def queryBooks(self, request):
"""Return books based on query."""
self._ensureAdmin()
q = Book.query()
#TODO: get projection, not all columns
if request.sbId:
q = q.filter( ndb.AND(
Book.sbId >= request.sbId.upper(),
Book.sbId < request.sbId.upper() + 'Z' ))
q = q.order(Book.sbId)
elif request.name:
q = q.filter( ndb.AND(
Book.title >= request.name.lower(),
Book.title < request.name.lower() + 'z'))
q = q.order(Book.title)
curs = Cursor(urlsafe=request.cursor)
books, nextcurs, more = q.fetch_page(PAGE_SIZE, start_cursor=curs)
nextcursor = None
if more and nextcurs:
nextcursor = nextcurs.urlsafe()
return BookForms(items = [self._copyBookToForm(book) \
for book in books], cursor = nextcursor)
示例4: _getOverDue
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import query [as 别名]
def _getOverDue():
"""returns the email ids and messages for overdue checkouts"""
overdueCheckouts = Book.query(
ndb.AND(Book.dueDate != None,
Book.dueDate < date.today())).fetch()
#create a dictionary so we can consolidate the books per email
overDueDict = {}
for checkout in overdueCheckouts:
email = ndb.Key(Student, checkout.studentId).get().email
if not email in overDueDict:
overDueDict[email] = []
overDueDict[email].append(string.capwords(checkout.title))
overDueArr = []
for k, v in overDueDict.iteritems():
message = 'The following books are overdue:'+ \
' Please return them to Shishu Bharathi ASAP:\n'
for book in v:
message += book + '\n'
overDueArr.append((k, message))
return overDueArr
示例5: getCheckouts
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import query [as 别名]
def getCheckouts(self, request):
"""get checkout records"""
self._ensureAdmin()
q = Book.query(Book.checkedOut == True)
return CheckoutForms(items = [self._copyCheckoutToForm(checkout) \
for checkout in q])
示例6: getBooks
# 需要导入模块: from models import Book [as 别名]
# 或者: from models.Book import query [as 别名]
def getBooks(self, request):
"""Return all books."""
self._ensureAdmin()
q = Book.query()
return BookForms(items = [self._copyBookToForm(book) \
for book in q])