本文整理匯總了Python中models.Email.find方法的典型用法代碼示例。如果您正苦於以下問題:Python Email.find方法的具體用法?Python Email.find怎麽用?Python Email.find使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Email
的用法示例。
在下文中一共展示了Email.find方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_queryset
# 需要導入模塊: from models import Email [as 別名]
# 或者: from models.Email import find [as 別名]
def get_queryset(self):
selector = {}
for k, v in self.request.GET.items():
if v and k!='page':
if k in self.header_fields:
k = 'header.' + k
#TODO pretty unsafe to use user's input directly
# TOO DANGEROUS OF NOSQL INJECTION
selector[k] = {'$regex': '.*%s.*' % re.escape(v)}
# Try using the python regex objects instead. Pymongo will serialize them properly
# selector[k] = {'$regex': '.*%s.*' % re.escape(v), '$options': 'i'}
# We have a middleware to set remote_addr
logger.info('Selector is %s', selector, extra=self.request.__dict__)
cursor = Email.find(**selector)
paginator = Paginator(cursor, 20) # Show 20 contacts per page
# pdb.set_trace()
page = self.request.GET.get('page')
try:
emails = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
emails = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
emails = paginator.page(paginator.num_pages)
return emails