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