• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.parse_query函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sentry.search.utils.parse_query函数的典型用法代码示例。如果您正苦于以下问题:Python parse_query函数的具体用法?Python parse_query怎么用?Python parse_query使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: _build_query_params_from_request

    def _build_query_params_from_request(self, request, project):
        query_kwargs = {
            'project': project,
            'sort_by': request.GET.get('sort', DEFAULT_SORT_OPTION),
        }

        limit = request.GET.get('limit')
        if limit:
            try:
                query_kwargs['limit'] = int(limit)
            except ValueError:
                raise ValidationError('invalid limit')

        # TODO: proper pagination support
        cursor = request.GET.get('cursor')
        if cursor:
            query_kwargs['cursor'] = Cursor.from_string(cursor)

        query = request.GET.get('query', 'is:unresolved').strip()
        if query:
            try:
                query_kwargs.update(parse_query(project, query, request.user))
            except InvalidQuery as e:
                raise ValidationError(
                    u'Your search query could not be parsed: {}'.format(
                        e.message)
                )

        return query_kwargs
开发者ID:hosmelq,项目名称:sentry,代码行数:29,代码来源:project_group_index.py


示例2: get

    def get(self, request, group):
        """
        List an Issue's Events
        ``````````````````````

        This endpoint lists an issue's events.

        :pparam string issue_id: the ID of the issue to retrieve.
        :auth: required
        """

        events = Event.objects.filter(group_id=group.id)

        query = request.GET.get("query")
        if query:
            query_kwargs = parse_query(group.project, query, request.user)

            if query_kwargs["query"]:
                events = events.filter(message__icontains=query_kwargs["query"])

            if query_kwargs["tags"]:
                events = events.filter(id__in=self._tags_to_filter(group, query_kwargs["tags"]))

        return self.paginate(
            request=request,
            queryset=events,
            order_by="-datetime",
            on_results=lambda x: serialize(x, request.user),
            paginator_cls=DateTimePaginator,
        )
开发者ID:pombredanne,项目名称:django-sentry,代码行数:30,代码来源:group_events.py


示例3: _get_search_query_and_tags

    def _get_search_query_and_tags(self, request, group, environments=None):
        raw_query = request.GET.get('query')

        if raw_query:
            query_kwargs = parse_query([group.project], raw_query, request.user, environments)
            query = query_kwargs.pop('query', None)
            tags = query_kwargs.pop('tags', {})
        else:
            query = None
            tags = {}

        if environments:
            env_names = set(env.name for env in environments)
            if 'environment' in tags:
                # If a single environment was passed as part of the query, then
                # we'll just search for that individual environment in this
                # query, even if more are selected.
                if tags['environment'] not in env_names:
                    # An event can only be associated with a single
                    # environment, so if the environments associated with
                    # the request don't contain the environment provided as a
                    # tag lookup, the query cannot contain any valid results.
                    raise NoResults
            else:
                # XXX: Handle legacy backends here. Just store environment as a
                # single tag if we only have one so that we don't break existing
                # usage.
                tags['environment'] = list(env_names) if len(env_names) > 1 else env_names.pop()

        return query, tags
开发者ID:getsentry,项目名称:sentry,代码行数:30,代码来源:group_events.py


示例4: _build_query_params_from_request

    def _build_query_params_from_request(self, request, project):
        query_kwargs = {
            'project': project,
        }

        if request.GET.get('status'):
            try:
                query_kwargs['status'] = STATUS_CHOICES[request.GET['status']]
            except KeyError:
                raise ValidationError('invalid status')

        if request.user.is_authenticated() and request.GET.get('bookmarks'):
            query_kwargs['bookmarked_by'] = request.user

        if request.user.is_authenticated() and request.GET.get('assigned'):
            query_kwargs['assigned_to'] = request.user

        sort_by = request.GET.get('sort')
        if sort_by is None:
            sort_by = DEFAULT_SORT_OPTION

        query_kwargs['sort_by'] = sort_by

        tags = {}
        for tag_key in TagKey.objects.all_keys(project):
            if request.GET.get(tag_key):
                tags[tag_key] = request.GET[tag_key]
        if tags:
            query_kwargs['tags'] = tags

        limit = request.GET.get('limit')
        if limit:
            try:
                query_kwargs['limit'] = int(limit)
            except ValueError:
                raise ValidationError('invalid limit')

        # TODO: proper pagination support
        cursor = request.GET.get('cursor')
        if cursor:
            query_kwargs['cursor'] = Cursor.from_string(cursor)

        query = request.GET.get('query', 'is:unresolved').strip()
        if query:
            try:
                query_kwargs.update(parse_query(project, query, request.user))
            except InvalidQuery as e:
                raise ValidationError(u'Your search query could not be parsed: {}'.format(e.message))

        return query_kwargs
开发者ID:rlugojr,项目名称:sentry,代码行数:50,代码来源:project_group_index.py


示例5: get

    def get(self, request, group):
        """
        List an Issue's Events
        ``````````````````````

        This endpoint lists an issue's events.

        :pparam string issue_id: the ID of the issue to retrieve.
        :auth: required
        """

        events = Event.objects.filter(
            group_id=group.id,
        )

        query = request.GET.get('query')
        if query:
            try:
                query_kwargs = parse_query(group.project, query, request.user)
            except InvalidQuery as exc:
                return Response({'detail': six.text_type(exc)}, status=400)

            if query_kwargs['query']:
                events = events.filter(
                    message__icontains=query_kwargs['query'],
                )

            if query_kwargs['tags']:
                event_ids = tagstore.get_group_event_ids(
                    group.project_id, group.id, query_kwargs['tags'])
                if event_ids:
                    events = events.filter(
                        id__in=event_ids,
                    )
                else:
                    events = events.none()

        return self.paginate(
            request=request,
            queryset=events,
            order_by='-datetime',
            on_results=lambda x: serialize(x, request.user),
            paginator_cls=DateTimePaginator,
        )
开发者ID:NuttasitBoonwat,项目名称:sentry,代码行数:44,代码来源:group_events.py


示例6: test_tag_with_colon_in_value

 def test_tag_with_colon_in_value(self):
     result = parse_query('url:http://example.com', self.user)
     assert result == {'tags': {'url': 'http://example.com'}, 'query': ''}
开发者ID:carriercomm,项目名称:sentry-1,代码行数:3,代码来源:test_utils.py


示例7: test_simple

 def test_simple(self):
     result = parse_query('foo bar', self.user)
     assert result == {'tags': {}, 'query': 'foo bar'}
开发者ID:carriercomm,项目名称:sentry-1,代码行数:3,代码来源:test_utils.py


示例8: test_release

 def test_release(self):
     result = parse_query('release:bar', self.user)
     assert result == {'tags': {'sentry:release': 'bar'}, 'query': ''}
开发者ID:carriercomm,项目名称:sentry-1,代码行数:3,代码来源:test_utils.py


示例9: test_assigned_unknown_user

 def test_assigned_unknown_user(self):
     result = parse_query('assigned:[email protected]', self.user)
     assert result['assigned_to'].id == 0
开发者ID:carriercomm,项目名称:sentry-1,代码行数:3,代码来源:test_utils.py


示例10: test_assigned_me

 def test_assigned_me(self):
     result = parse_query('assigned:me', self.user)
     assert result == {'assigned_to': self.user, 'tags': {}, 'query': ''}
开发者ID:carriercomm,项目名称:sentry-1,代码行数:3,代码来源:test_utils.py


示例11: test_tag_with_quotes_and_query

 def test_tag_with_quotes_and_query(self):
     result = parse_query('key:"a value" hello', self.user)
     assert result == {'tags': {'key': 'a value'}, 'query': 'hello'}
开发者ID:carriercomm,项目名称:sentry-1,代码行数:3,代码来源:test_utils.py


示例12: get


#.........这里部分代码省略.........
            stats_period = '24h'
        elif stats_period == '':
            # disable stats
            stats_period = None

        if request.GET.get('status'):
            try:
                query_kwargs['status'] = STATUS_CHOICES[request.GET['status']]
            except KeyError:
                return Response('{"detail": "invalid status"}', status=400)

        if request.user.is_authenticated() and request.GET.get('bookmarks'):
            query_kwargs['bookmarked_by'] = request.user

        if request.user.is_authenticated() and request.GET.get('assigned'):
            query_kwargs['assigned_to'] = request.user

        sort_by = request.GET.get('sort')
        if sort_by is None:
            sort_by = DEFAULT_SORT_OPTION

        query_kwargs['sort_by'] = sort_by

        tags = {}
        for tag_key in TagKey.objects.all_keys(project):
            if request.GET.get(tag_key):
                tags[tag_key] = request.GET[tag_key]
        if tags:
            query_kwargs['tags'] = tags

        # TODO: dates should include timestamps
        date_from = request.GET.get('since')
        date_to = request.GET.get('until')
        date_filter = request.GET.get('date_filter')

        limit = request.GET.get('limit')
        if limit:
            try:
                query_kwargs['limit'] = int(limit)
            except ValueError:
                return Response('{"detail": "invalid limit"}', status=400)

        if date_from:
            date_from = self._parse_date(date_from)

        if date_to:
            date_to = self._parse_date(date_to)

        query_kwargs['date_from'] = date_from
        query_kwargs['date_to'] = date_to
        if date_filter:
            query_kwargs['date_filter'] = date_filter

        # TODO: proper pagination support
        cursor = request.GET.get('cursor')
        if cursor:
            query_kwargs['cursor'] = Cursor.from_string(cursor)

        query = request.GET.get('query', 'is:unresolved').strip()
        if len(query) == 32:
            # check to see if we've got an event ID
            try:
                matching_event = EventMapping.objects.filter(
                    project=project,
                    event_id=query,
                ).select_related('group')[0]
            except IndexError:
                pass
            else:
                return Response(serialize(
                    [matching_event.group], request.user, StreamGroupSerializer(
                        stats_period=stats_period
                    )
                ))

        if query is not None:
            query_kwargs.update(parse_query(query, request.user))

        cursor_result = search.query(**query_kwargs)

        results = list(cursor_result)

        # HACK: remove auto resolved entries
        if query_kwargs.get('status') == STATUS_UNRESOLVED:
            results = [
                r for r in results
                if not r.is_resolved()
            ]

        response = Response(serialize(
            results, request.user, StreamGroupSerializer(
                stats_period=stats_period
            )
        ))
        response['Link'] = ', '.join([
            self.build_cursor_link(request, 'previous', cursor_result.prev),
            self.build_cursor_link(request, 'next', cursor_result.next),
        ])

        return response
开发者ID:hyserver,项目名称:sentry,代码行数:101,代码来源:project_group_index.py


示例13: parse_query

 def parse_query(self, query):
     return parse_query([self.project], query, self.user, None)
开发者ID:yaoqi,项目名称:sentry,代码行数:2,代码来源:test_utils.py


示例14: get

    def get(self, request, group):
        """
        List an Issue's Events
        ``````````````````````

        This endpoint lists an issue's events.

        :pparam string issue_id: the ID of the issue to retrieve.
        :auth: required
        """

        def respond(queryset):
            return self.paginate(
                request=request,
                queryset=queryset,
                order_by='-datetime',
                on_results=lambda x: serialize(x, request.user),
                paginator_cls=DateTimePaginator,
            )

        events = Event.objects.filter(group_id=group.id)

        try:
            environment = self._get_environment_from_request(
                request,
                group.project.organization_id,
            )
        except Environment.DoesNotExist:
            return respond(events.none())

        raw_query = request.GET.get('query')

        if raw_query:
            try:
                query_kwargs = parse_query(group.project, raw_query, request.user)
            except InvalidQuery as exc:
                return Response({'detail': six.text_type(exc)}, status=400)
            else:
                query = query_kwargs.pop('query', None)
                tags = query_kwargs.pop('tags', {})
        else:
            query = None
            tags = {}

        if environment is not None:
            if 'environment' in tags and tags['environment'] != environment.name:
                # An event can only be associated with a single
                # environment, so if the environment associated with
                # the request is different than the environment
                # provided as a tag lookup, the query cannot contain
                # any valid results.
                return respond(events.none())
            else:
                tags['environment'] = environment.name

        if query:
            q = Q(message__icontains=query)

            if len(query) == 32:
                q |= Q(event_id__exact=query)

            events = events.filter(q)

        if tags:
            event_ids = tagstore.get_group_event_ids(
                group.project_id,
                group.id,
                environment.id if environment is not None else None,
                tags,
            )

            if not event_ids:
                return respond(events.none())

            events = events.filter(id__in=event_ids)

        # filter out events which are beyond the retention period
        retention = quotas.get_event_retention(organization=group.project.organization)
        if retention:
            events = events.filter(
                datetime__gte=timezone.now() - timedelta(days=retention)
            )

        return respond(events)
开发者ID:hosmelq,项目名称:sentry,代码行数:84,代码来源:group_events.py


示例15: _build_query_params_from_request

    def _build_query_params_from_request(self, request, project):
        query_kwargs = {
            'project': project,
        }

        if request.GET.get('status'):
            try:
                query_kwargs['status'] = STATUS_CHOICES[request.GET['status']]
            except KeyError:
                raise ValidationError('invalid status')

        if request.user.is_authenticated() and request.GET.get('bookmarks'):
            query_kwargs['bookmarked_by'] = request.user

        if request.user.is_authenticated() and request.GET.get('assigned'):
            query_kwargs['assigned_to'] = request.user

        sort_by = request.GET.get('sort')
        if sort_by is None:
            sort_by = DEFAULT_SORT_OPTION

        query_kwargs['sort_by'] = sort_by

        tags = {}
        for tag_key in TagKey.objects.all_keys(project):
            if request.GET.get(tag_key):
                tags[tag_key] = request.GET[tag_key]
        if tags:
            query_kwargs['tags'] = tags

        # TODO: dates should include timestamps
        date_from = request.GET.get('since')
        date_to = request.GET.get('until')
        date_filter = request.GET.get('date_filter')

        limit = request.GET.get('limit')
        if limit:
            try:
                query_kwargs['limit'] = int(limit)
            except ValueError:
                raise ValidationError('invalid limit')

        if date_from:
            date_from = self._parse_date(date_from)

        if date_to:
            date_to = self._parse_date(date_to)

        query_kwargs['date_from'] = date_from
        query_kwargs['date_to'] = date_to
        if date_filter:
            query_kwargs['date_filter'] = date_filter

        # TODO: proper pagination support
        cursor = request.GET.get('cursor')
        if cursor:
            query_kwargs['cursor'] = Cursor.from_string(cursor)

        query = request.GET.get('query', 'is:unresolved').strip()
        if query:
            query_kwargs.update(parse_query(project, query, request.user))

        return query_kwargs
开发者ID:zsh2938,项目名称:sentry,代码行数:63,代码来源:project_group_index.py


示例16: test_multiple_tags

 def test_multiple_tags(self):
     result = parse_query('foo:bar key:value', self.user)
     assert result == {'tags': {'key': 'value', 'foo': 'bar'}, 'query': ''}
开发者ID:carriercomm,项目名称:sentry-1,代码行数:3,代码来源:test_utils.py


示例17: test_single_tag_with_quotes

 def test_single_tag_with_quotes(self):
     result = parse_query('foo:"bar"', self.user)
     assert result == {'tags': {'foo': 'bar'}, 'query': ''}
开发者ID:carriercomm,项目名称:sentry-1,代码行数:3,代码来源:test_utils.py


示例18: parse_query

 def parse_query(self, query):
     return parse_query(self.project, query, self.user)
开发者ID:Natim,项目名称:sentry,代码行数:2,代码来源:test_utils.py


示例19: test_is_resolved

 def test_is_resolved(self):
     result = parse_query('is:resolved', self.user)
     assert result == {'status': GroupStatus.RESOLVED, 'tags': {}, 'query': ''}
开发者ID:carriercomm,项目名称:sentry-1,代码行数:3,代码来源:test_utils.py


示例20: _get_group_list

def _get_group_list(request, project):
    query_kwargs = {"project": project}

    status = request.GET.get("status", "0")
    if status:
        query_kwargs["status"] = int(status)

    if request.user.is_authenticated() and request.GET.get("bookmarks"):
        query_kwargs["bookmarked_by"] = request.user

    if request.user.is_authenticated() and request.GET.get("assigned"):
        query_kwargs["assigned_to"] = request.user

    sort_by = request.GET.get("sort") or request.session.get("streamsort")
    if sort_by is None:
        sort_by = DEFAULT_SORT_OPTION

    # Save last sort in session
    if sort_by != request.session.get("streamsort"):
        request.session["streamsort"] = sort_by

    query_kwargs["sort_by"] = sort_by

    tags = {}
    for tag_key in TagKey.objects.all_keys(project):
        if request.GET.get(tag_key):
            tags[tag_key] = request.GET[tag_key]

    if tags:
        query_kwargs["tags"] = tags
    else:
        query_kwargs["tags"] = {}

    date_from = request.GET.get("df")
    time_from = request.GET.get("tf")
    date_to = request.GET.get("dt")
    time_to = request.GET.get("tt")
    date_filter = request.GET.get("date_type")

    today = timezone.now()
    # date format is Y-m-d
    if any(x is not None for x in [date_from, time_from, date_to, time_to]):
        date_from, date_to = parse_date(date_from, time_from), parse_date(date_to, time_to)
    else:
        date_from = today - datetime.timedelta(days=5)
        date_to = None

    query_kwargs["date_from"] = date_from
    query_kwargs["date_to"] = date_to
    if date_filter:
        query_kwargs["date_filter"] = date_filter

    cursor = request.GET.get("cursor")
    if cursor:
        try:
            query_kwargs["cursor"] = Cursor.from_string(cursor)
        except ValueError:
            # XXX(dcramer): ideally we'd error, but this is an internal API so
            # we'd rather just throw it away
            logging.info("Throwing away invalid cursor: %s", cursor)
    query_kwargs["limit"] = EVENTS_PER_PAGE

    query = request.GET.get("query", "")
    if query is not None:
        query_result = parse_query(query, request.user)
        # Disclaimer: the following code is disgusting
        if query_result.get("query"):
            query_kwargs["query"] = query_result["query"]
        if query_result.get("tags"):
            query_kwargs["tags"].update(query_result["tags"])

    results = app.search.query(**query_kwargs)

    return {
        "event_list": results[:EVENTS_PER_PAGE],
        "date_from": date_from,
        "date_to": date_to,
        "today": today,
        "sort": sort_by,
        "date_type": date_filter,
        "next_cursor": results.next,
        "prev_cursor": results.prev,
    }
开发者ID:alfonsolzrg,项目名称:sentry,代码行数:83,代码来源:groups.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python event_processed.send函数代码示例发布时间:2022-05-27
下一篇:
Python initializer.bootstrap_options函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap