本文整理汇总了Python中sentry.search.utils.parse_query函数的典型用法代码示例。如果您正苦于以下问题:Python parse_query函数的具体用法?Python parse_query怎么用?Python parse_query使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_query函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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,
)
示例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
示例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
示例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,
)
示例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': ''}
示例7: test_simple
def test_simple(self):
result = parse_query('foo bar', self.user)
assert result == {'tags': {}, 'query': 'foo bar'}
示例8: test_release
def test_release(self):
result = parse_query('release:bar', self.user)
assert result == {'tags': {'sentry:release': 'bar'}, 'query': ''}
示例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
示例10: test_assigned_me
def test_assigned_me(self):
result = parse_query('assigned:me', self.user)
assert result == {'assigned_to': self.user, 'tags': {}, 'query': ''}
示例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'}
示例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
示例13: parse_query
def parse_query(self, query):
return parse_query([self.project], query, self.user, None)
示例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)
示例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