本文整理汇总了Python中pyvac.models.User.get_all_nicknames方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_all_nicknames方法的具体用法?Python User.get_all_nicknames怎么用?Python User.get_all_nicknames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvac.models.User
的用法示例。
在下文中一共展示了User.get_all_nicknames方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import get_all_nicknames [as 别名]
def render(self):
def fmt_req_type(req):
label = ' %s' % req.label if req.label else ''
return '%s%s' % (req.type, label)
filter_nick = self.request.params.get('nick')
filter_name = self.request.params.get('name')
filter_date = self.request.params.get('date')
# strict if provided will disable partial search for nicknames
strict = self.request.params.get('strict')
# remove unwanted chars from filter_date
if filter_date:
filter_date = re.sub('[^\d+]', '', filter_date)
if filter_nick:
# retrieve all availables nicknames
all_nick = [nick.lower()
for nick in User.get_all_nicknames(self.session)]
if strict:
match = filter_nick.lower() in all_nick
else:
match = set([nick for nick in all_nick
if filter_nick.lower() in nick.lower()])
if not match:
# filter_nick does not match any known uid, stop here
return JsonHTTPNotFound({'message': ('%s not found'
% filter_nick)})
requests = Request.get_active(self.session, filter_date)
data_name = dict([(req.user.name.lower(), fmt_req_type(req))
for req in requests])
data_nick = dict([(req.user.nickname, fmt_req_type(req))
for req in requests])
ret = val = None
if filter_nick:
val = data_nick.get(filter_nick.lower())
if val:
ret = {filter_nick: val}
elif not strict:
val = dict([(k, v) for k, v in data_nick.items()
if filter_nick.lower() in k])
return val
else:
return {}
if filter_name:
val = data_name.get(filter_name.lower())
if val:
ret = {filter_name: val}
else:
val = dict([(k, v) for k, v in data_name.items()
if filter_name.lower() in k])
return val
return ret if ret else data_name