python类or_()的实例源码

common.py 文件源码 项目:django-elasticsearch-dsl-drf 作者: barseghyanartur 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def apply_query_exclude(cls, queryset, options, value):
        """Apply `exclude` functional query.

        :param queryset: Original queryset.
        :param options: Filter options.
        :param value: value to filter on.
        :type queryset: elasticsearch_dsl.search.Search
        :type options: dict
        :type value: str
        :return: Modified queryset.
        :rtype: elasticsearch_dsl.search.Search
        """
        __values = cls.split_lookup_value(value)

        __queries = []
        for __value in __values:
            __queries.append(
                ~Q('term', **{options['field']: __value})
            )

        if __queries:
            queryset = queryset.query(
                six.moves.reduce(operator.or_, __queries)
            )

        return queryset
__init__.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test(cls, nodelist):
        # MUST NOT short-circuit evaluation, or invalid syntax can be skipped!
        items = [
            cls.interpret(nodelist[i])
            for i in range(1, len(nodelist), 2)
        ]
        return functools.reduce(operator.or_, items)
__init__.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test(cls, nodelist):
        # MUST NOT short-circuit evaluation, or invalid syntax can be skipped!
        items = [
            cls.interpret(nodelist[i])
            for i in range(1, len(nodelist), 2)
        ]
        return functools.reduce(operator.or_, items)
test_tryton.py 文件源码 项目:health-mosconi 作者: GNUHealth-Mosconi 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_menu_action(self):
        'Test that menu actions are accessible to menu\'s group'
        with Transaction().start(DB_NAME, USER, context=CONTEXT):
            pool = Pool()
            Menu = pool.get('ir.ui.menu')
            ModelData = pool.get('ir.model.data')

            module_menus = ModelData.search([
                    ('model', '=', 'ir.ui.menu'),
                    ('module', '=', self.module),
                    ])
            menus = Menu.browse([mm.db_id for mm in module_menus])
            for menu, module_menu in zip(menus, module_menus):
                if not menu.action_keywords:
                    continue
                menu_groups = set(menu.groups)
                actions_groups = reduce(operator.or_,
                    (set(k.action.groups) for k in menu.action_keywords
                        if k.keyword == 'tree_open'))
                if not actions_groups:
                    continue
                assert menu_groups <= actions_groups, (
                    'Menu "%(menu_xml_id)s" actions are not accessible to '
                    '%(groups)s' % {
                        'menu_xml_id': module_menu.fs_id,
                        'groups': ','.join(g.name
                            for g in menu_groups - actions_groups),
                        })
options.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def get_search_results(self, request, queryset, search_term):
        """
        Returns a tuple containing a queryset to implement the search,
        and a boolean indicating if the results may contain duplicates.
        """
        # Apply keyword searches.
        def construct_search(field_name):
            if field_name.startswith('^'):
                return "%s__istartswith" % field_name[1:]
            elif field_name.startswith('='):
                return "%s__iexact" % field_name[1:]
            elif field_name.startswith('@'):
                return "%s__search" % field_name[1:]
            else:
                return "%s__icontains" % field_name

        use_distinct = False
        search_fields = self.get_search_fields(request)
        if search_fields and search_term:
            orm_lookups = [construct_search(str(search_field))
                           for search_field in search_fields]
            for bit in search_term.split():
                or_queries = [models.Q(**{orm_lookup: bit})
                              for orm_lookup in orm_lookups]
                queryset = queryset.filter(reduce(operator.or_, or_queries))
            if not use_distinct:
                for search_spec in orm_lookups:
                    if lookup_needs_distinct(self.opts, search_spec):
                        use_distinct = True
                        break

        return queryset, use_distinct
__init__.py 文件源码 项目:zanph 作者: zanph 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test(cls, nodelist):
        # MUST NOT short-circuit evaluation, or invalid syntax can be skipped!
        items = [
            cls.interpret(nodelist[i])
            for i in range(1, len(nodelist), 2)
        ]
        return functools.reduce(operator.or_, items)
options.py 文件源码 项目:NarshaTech 作者: KimJangHyeon 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_search_results(self, request, queryset, search_term):
        """
        Returns a tuple containing a queryset to implement the search,
        and a boolean indicating if the results may contain duplicates.
        """
        # Apply keyword searches.
        def construct_search(field_name):
            if field_name.startswith('^'):
                return "%s__istartswith" % field_name[1:]
            elif field_name.startswith('='):
                return "%s__iexact" % field_name[1:]
            elif field_name.startswith('@'):
                return "%s__search" % field_name[1:]
            else:
                return "%s__icontains" % field_name

        use_distinct = False
        search_fields = self.get_search_fields(request)
        if search_fields and search_term:
            orm_lookups = [construct_search(str(search_field))
                           for search_field in search_fields]
            for bit in search_term.split():
                or_queries = [models.Q(**{orm_lookup: bit})
                              for orm_lookup in orm_lookups]
                queryset = queryset.filter(reduce(operator.or_, or_queries))
            if not use_distinct:
                for search_spec in orm_lookups:
                    if lookup_needs_distinct(self.opts, search_spec):
                        use_distinct = True
                        break

        return queryset, use_distinct
peewee.py 文件源码 项目:harbour-mercury 作者: chstem 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def orwhere(self, *expressions):
        self._where = self._add_query_clauses(
            self._where, expressions, operator.or_)
pkg_resources.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test(cls, nodelist):
        # MUST NOT short-circuit evaluation, or invalid syntax can be skipped!
        return functools.reduce(operator.or_, [cls.interpret(nodelist[i]) for i in range(1,len(nodelist),2)])
fsa.py 文件源码 项目:nstock 作者: ybenitezf 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def union(dfa1, dfa2):
    return product(dfa1, operator.or_, dfa2)
lookups.py 文件源码 项目:pyconjp-website 作者: pyconjp 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_query(self, request, term):
        qs = self.get_queryset()
        if term:
            search_filters = []
            if len(term.split()) == 1:
                if self.search_fields:
                    for field in self.search_fields:
                        search_filters.append(Q(**{field: term}))
                qs = qs.filter(reduce(operator.or_, search_filters))
            else:
                # Accounts for 'John Doe' term; will compare against get_full_name
                term = term.lower()
                qs = [x for x in qs if term in x.get_full_name().lower()]
        return qs
api.py 文件源码 项目:zing 作者: evernote 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_search_filter(self, keyword):
        search_fields = getattr(self, 'search_fields', None)
        if search_fields is None:
            search_fields = self.fields  # Assume all fields

        field_queries = list(
            zip(map(lambda x: '%s__icontains' % x, search_fields),
                (keyword,)*len(search_fields))
        )
        lookups = [Q(x) for x in field_queries]

        return reduce(operator.or_, lookups)
fpconst.py 文件源码 项目:p2pool-bch 作者: amarian12 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _zero_mantissa(dval):
    """Determine whether the mantissa bits of the given double are all
    zero."""
    bb = _double_as_bytes(dval)
    return ((bb[1] & 0x0f) | reduce(operator.or_, bb[2:])) == 0

##
## Functions to test for IEEE 754 special values
##
options.py 文件源码 项目:Scrum 作者: prakharchoudhary 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_search_results(self, request, queryset, search_term):
        """
        Returns a tuple containing a queryset to implement the search,
        and a boolean indicating if the results may contain duplicates.
        """
        # Apply keyword searches.
        def construct_search(field_name):
            if field_name.startswith('^'):
                return "%s__istartswith" % field_name[1:]
            elif field_name.startswith('='):
                return "%s__iexact" % field_name[1:]
            elif field_name.startswith('@'):
                return "%s__search" % field_name[1:]
            else:
                return "%s__icontains" % field_name

        use_distinct = False
        search_fields = self.get_search_fields(request)
        if search_fields and search_term:
            orm_lookups = [construct_search(str(search_field))
                           for search_field in search_fields]
            for bit in search_term.split():
                or_queries = [models.Q(**{orm_lookup: bit})
                              for orm_lookup in orm_lookups]
                queryset = queryset.filter(reduce(operator.or_, or_queries))
            if not use_distinct:
                for search_spec in orm_lookups:
                    if lookup_needs_distinct(self.opts, search_spec):
                        use_distinct = True
                        break

        return queryset, use_distinct
test_ndarray_elementwise_op.py 文件源码 项目:cupy 作者: cupy 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_or_scalar(self):
        self.check_array_scalar_op(operator.or_)
test_ndarray_elementwise_op.py 文件源码 项目:cupy 作者: cupy 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_or_scalarzero(self):
        self.check_array_scalarzero_op(operator.or_)
test_ndarray_elementwise_op.py 文件源码 项目:cupy 作者: cupy 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_ror_scalarzero(self):
        self.check_array_scalarzero_op(operator.or_, swap=True)
test_ndarray_elementwise_op.py 文件源码 项目:cupy 作者: cupy 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_or_array(self):
        self.check_array_array_op(operator.or_)
test_ndarray_elementwise_op.py 文件源码 项目:cupy 作者: cupy 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_doubly_broadcasted_or(self):
        self.check_array_doubly_broadcasted_op(operator.or_)
common.py 文件源码 项目:cerberus-core 作者: ovh 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def get_user_filters(user):
    """
        Returns `django.db.models.query.QuerySet` filters based on allowed category for given user
    """
    where = [Q()]
    user_specific_where = []
    abuse_permissions = AbusePermission.objects.filter(user=user.id)

    for perm in abuse_permissions:
        if perm.profile.name == 'Expert':
            user_specific_where.append(Q(category=perm.category))
        elif perm.profile.name == 'Advanced':
            user_specific_where.append(Q(category=perm.category, confidential=False))
        elif perm.profile.name == 'Beginner':
            user_specific_where.append(Q(
                priority__in=USER_FILTERS_BEGINNER_PRIORITY,
                category=perm.category,
                confidential=False,
                escalated=False,
                moderation=False
            ))

    if len(user_specific_where):
        user_specific_where = reduce(operator.or_, user_specific_where)
        where.append(user_specific_where)
    else:
        # If no category allowed
        where.append(Q(category=None))

    return where


问题


面经


文章

微信
公众号

扫码关注公众号