当前位置: 首页>>代码示例>>Python>>正文


Python Request.get_active方法代码示例

本文整理汇总了Python中pyvac.models.Request.get_active方法的典型用法代码示例。如果您正苦于以下问题:Python Request.get_active方法的具体用法?Python Request.get_active怎么用?Python Request.get_active使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyvac.models.Request的用法示例。


在下文中一共展示了Request.get_active方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render

# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import get_active [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
开发者ID:doyousoft,项目名称:pyvac,代码行数:59,代码来源:request.py


注:本文中的pyvac.models.Request.get_active方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。