event_list = filter_.get_query_set(event_list) except Exception, e: logger = logging.getLogger('sentry.filters') logger.exception('Error processing filter %r: %s', cls, e) 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_type = 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 if date_type == 'first_seen': if date_from: event_list = event_list.filter(first_seen__gte=date_from) elif date_to: event_list = event_list.filter(first_seen__lte=date_to) else: if date_from and date_to: event_list = event_list.filter( groupcountbyminute__date__gte=date_from, groupcountbyminute__date__lte=date_to,
def _get_group_list(request, project): filters = [] for cls in get_filters(Group, project): try: filters.append(cls(request, project)) except Exception as e: logger = logging.getLogger('sentry.filters') logger.exception('Error initializing filter %r: %s', cls, e) event_list = Group.objects if request.user.is_authenticated() and request.GET.get('bookmarks'): event_list = event_list.filter( bookmark_set__project=project, bookmark_set__user=request.user, ) else: event_list = event_list.filter(project=project) for filter_ in filters: try: if not filter_.is_set(): continue event_list = filter_.get_query_set(event_list) except Exception as e: logger = logging.getLogger('sentry.filters') logger.exception('Error processing filter %r: %s', cls, e) 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_type = 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 if date_type == 'first_seen': if date_from: event_list = event_list.filter(first_seen__gte=date_from) elif date_to: event_list = event_list.filter(first_seen__lte=date_to) else: if date_from and date_to: event_list = event_list.filter( groupcountbyminute__date__gte=date_from, groupcountbyminute__date__lte=date_to, ) elif date_from: event_list = event_list.filter(last_seen__gte=date_from) elif date_to: event_list = event_list.filter(last_seen__lte=date_to) sort = request.GET.get('sort') or request.session.get('streamsort') if sort not in SORT_OPTIONS: sort = DEFAULT_SORT_OPTION # Save last sort in session if sort != request.session.get('streamsort'): request.session['streamsort'] = sort if sort.startswith('accel_') and not has_trending(): sort = DEFAULT_SORT_OPTION engine = get_db_engine('default') if engine.startswith('sqlite'): score_clause = SQLITE_SORT_CLAUSES.get(sort) filter_clause = SQLITE_SCORE_CLAUSES.get(sort) elif engine.startswith('mysql'): score_clause = MYSQL_SORT_CLAUSES.get(sort) filter_clause = MYSQL_SCORE_CLAUSES.get(sort) elif engine.startswith('oracle'): score_clause = ORACLE_SORT_CLAUSES.get(sort) filter_clause = ORACLE_SCORE_CLAUSES.get(sort) elif engine in ('django_pytds', 'sqlserver_ado', 'sql_server.pyodbc'): score_clause = MSSQL_SORT_CLAUSES.get(sort) filter_clause = MSSQL_SCORE_CLAUSES.get(sort) else: score_clause = SORT_CLAUSES.get(sort) filter_clause = SCORE_CLAUSES.get(sort) # IMPORTANT: All filters must already be applied once we reach this point if sort == 'tottime': event_list = event_list.filter(time_spent_count__gt=0) elif sort == 'avgtime': event_list = event_list.filter(time_spent_count__gt=0) elif sort.startswith('accel_'): event_list = Group.objects.get_accelerated([project.id], event_list, minutes=int( sort.split('_', 1)[1])) if score_clause: event_list = event_list.extra(select={'sort_value': score_clause}, ) # HACK: don't sort by the same column twice if sort == 'date': event_list = event_list.order_by('-last_seen') else: event_list = event_list.order_by('-sort_value', '-last_seen') cursor = request.GET.get('cursor', request.GET.get('c')) if cursor: event_list = event_list.extra( where=['%s > %%s' % filter_clause], params=[float(cursor)], ) return { 'filters': filters, 'event_list': event_list, 'date_from': date_from, 'date_to': date_to, 'today': today, 'sort': sort, 'date_type': date_type }
def _get_group_list(request, project): filters = [] for cls in get_filters(Group, project): try: filters.append(cls(request, project)) except Exception as e: logger = logging.getLogger('sentry.filters') logger.exception('Error initializing filter %r: %s', cls, e) event_list = Group.objects if request.user.is_authenticated() and request.GET.get('bookmarks'): event_list = event_list.filter( bookmark_set__project=project, bookmark_set__user=request.user, ) else: event_list = event_list.filter(project=project) for filter_ in filters: try: if not filter_.is_set(): continue event_list = filter_.get_query_set(event_list) except Exception as e: logger = logging.getLogger('sentry.filters') logger.exception('Error processing filter %r: %s', cls, e) 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_type = 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 if date_type == 'first_seen': if date_from: event_list = event_list.filter(first_seen__gte=date_from) elif date_to: event_list = event_list.filter(first_seen__lte=date_to) else: if date_from and date_to: event_list = event_list.filter( first_seen__gte=date_from, last_seen__lte=date_to, ) elif date_from: event_list = event_list.filter(last_seen__gte=date_from) elif date_to: event_list = event_list.filter(last_seen__lte=date_to) sort = request.GET.get('sort') or request.session.get('streamsort') if sort not in SORT_OPTIONS: sort = DEFAULT_SORT_OPTION # Save last sort in session if sort != request.session.get('streamsort'): request.session['streamsort'] = sort engine = get_db_engine('default') if engine.startswith('sqlite'): score_clause = SQLITE_SORT_CLAUSES.get(sort) filter_clause = SQLITE_SCORE_CLAUSES.get(sort) elif engine.startswith('mysql'): score_clause = MYSQL_SORT_CLAUSES.get(sort) filter_clause = MYSQL_SCORE_CLAUSES.get(sort) elif engine.startswith('oracle'): score_clause = ORACLE_SORT_CLAUSES.get(sort) filter_clause = ORACLE_SCORE_CLAUSES.get(sort) elif engine in ('django_pytds', 'sqlserver_ado', 'sql_server.pyodbc'): score_clause = MSSQL_SORT_CLAUSES.get(sort) filter_clause = MSSQL_SCORE_CLAUSES.get(sort) else: score_clause = SORT_CLAUSES.get(sort) filter_clause = SCORE_CLAUSES.get(sort) # IMPORTANT: All filters must already be applied once we reach this point if sort == 'tottime': event_list = event_list.filter(time_spent_count__gt=0) elif sort == 'avgtime': event_list = event_list.filter(time_spent_count__gt=0) if score_clause: event_list = event_list.extra( select={'sort_value': score_clause}, ) # HACK: don't sort by the same column twice if sort == 'date': event_list = event_list.order_by('-last_seen') else: event_list = event_list.order_by('-sort_value', '-last_seen') cursor = request.GET.get('cursor', request.GET.get('c')) if cursor: event_list = event_list.extra( where=['%s > %%s' % filter_clause], params=[float(cursor)], ) return { 'filters': filters, 'event_list': event_list, 'date_from': date_from, 'date_to': date_to, 'today': today, 'sort': sort, 'date_type': date_type }
def _get_group_list(request, project): query_kwargs = {"project": project} query = request.GET.get("query") if query: query_kwargs["query"] = query 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 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 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 # HACK(dcramer): this should be removed once the pagination component # is abstracted from the paginator tag try: page = int(request.GET.get("p", 1)) except (ValueError, TypeError): page = 1 query_kwargs["offset"] = (page - 1) * EVENTS_PER_PAGE query_kwargs["limit"] = EVENTS_PER_PAGE + 1 results = app.search.query(**query_kwargs) if len(results) == query_kwargs["limit"]: next_page = page + 1 else: next_page = None if page > 1: prev_page = page - 1 else: prev_page = None return { "event_list": results[:EVENTS_PER_PAGE], "date_from": date_from, "date_to": date_to, "today": today, "sort": sort_by, "date_type": date_filter, "previous_page": prev_page, "next_page": next_page, }
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, }
def _get_group_list(request, project): query_kwargs = { 'project': project, } query = request.GET.get('query') if query: query_kwargs['query'] = query 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 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 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 # HACK(dcramer): this should be removed once the pagination component # is abstracted from the paginator tag try: page = int(request.GET.get('p', 1)) except (ValueError, TypeError): page = 1 query_kwargs['offset'] = (page - 1) * EVENTS_PER_PAGE query_kwargs['limit'] = EVENTS_PER_PAGE + 1 results = app.search.query(**query_kwargs) if len(results) == query_kwargs['limit']: next_page = page + 1 else: next_page = None if page > 1: prev_page = page - 1 else: prev_page = None return { 'event_list': results[:EVENTS_PER_PAGE], 'date_from': date_from, 'date_to': date_to, 'today': today, 'sort': sort_by, 'date_type': date_filter, 'previous_page': prev_page, 'next_page': next_page, }
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, }
def _get_group_list(request, project): query_kwargs = { 'project': project, } query = request.GET.get('query') if query: query_kwargs['query'] = query 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 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 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', request.GET.get('c')) if cursor: query_kwargs['cursor'] = cursor results = app.search.query(**query_kwargs) return { 'event_list': results, 'date_from': date_from, 'date_to': date_to, 'today': today, 'sort': sort_by, 'date_type': date_filter, }
def _get_group_list(request, project): query_kwargs = { 'project': project, } query = request.GET.get('query') if query: query_kwargs['query'] = query 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 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 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', request.GET.get('c')) if cursor: query_kwargs['cursor'] = cursor results = app.search.query(**query_kwargs) return { 'event_list': results, 'date_from': date_from, 'date_to': date_to, 'today': today, 'sort': sort_by, 'date_type': date_filter, }
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: for key, value in parse_query(query, request.user).iteritems(): if key == 'tags': query_kwargs['tags'].update(value) else: query_kwargs[key] = value 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, }
def get(self, request, project_id): project = Project.objects.get( id=project_id, ) assert_perm(project, request.user, request.auth) group_list = Group.objects.all() if request.user.is_authenticated() and request.GET.get('bookmarks'): group_list = group_list.filter( bookmark_set__project=project, bookmark_set__user=request.user, ) else: group_list = group_list.filter(project=project) status = request.GET.get('status') if status: group_list = group_list.filter(status=int(status)) tag_keys = TagKey.objects.all_keys(project) for tag in tag_keys: value = request.GET.get(tag) if value: group_list = group_list.filter( grouptag__project=project, grouptag__key=tag, grouptag__value=value, ) # TODO: dates should include timestamps date_from = request.GET.get('since') time_from = request.GET.get('until') date_filter = request.GET.get('date_filter') date_to = request.GET.get('dt') time_to = request.GET.get('tt') 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 - timedelta(days=5) date_to = None if date_filter == 'first_seen': if date_from: group_list = group_list.filter(first_seen__gte=date_from) elif date_to: group_list = group_list.filter(first_seen__lte=date_to) else: # TODO(dcramer): a date_to no longer makes a lot of sense, and will # need corrected when search lands if date_from: group_list = group_list.filter(last_seen__gte=date_from) if date_to: group_list = group_list.filter(last_seen__lte=date_to) sort = request.GET.get('sort') or request.session.get('streamsort') if sort is None: sort = DEFAULT_SORT_OPTION elif sort not in SORT_OPTIONS or sort.startswith('accel_'): return HttpResponse(status=400) # Save last sort in session if sort != request.session.get('streamsort'): request.session['streamsort'] = sort engine = get_db_engine('default') if engine.startswith('sqlite'): score_clause = SQLITE_SORT_CLAUSES.get(sort) filter_clause = SQLITE_SCORE_CLAUSES.get(sort) elif engine.startswith('mysql'): score_clause = MYSQL_SORT_CLAUSES.get(sort) filter_clause = MYSQL_SCORE_CLAUSES.get(sort) elif engine.startswith('oracle'): score_clause = ORACLE_SORT_CLAUSES.get(sort) filter_clause = ORACLE_SCORE_CLAUSES.get(sort) elif engine in ('django_pytds', 'sqlserver_ado', 'sql_server.pyodbc'): score_clause = MSSQL_SORT_CLAUSES.get(sort) filter_clause = MSSQL_SCORE_CLAUSES.get(sort) else: score_clause = SORT_CLAUSES.get(sort) filter_clause = SCORE_CLAUSES.get(sort) assert score_clause if sort == 'tottime': group_list = group_list.filter(time_spent_count__gt=0) elif sort == 'avgtime': group_list = group_list.filter(time_spent_count__gt=0) group_list = group_list.extra( select={'sort_value': score_clause}, ) return self.paginate( request=request, queryset=group_list, order_by='-sort_value', on_results=lambda x: serialize(x, request.user), )
def _get_group_list(request, project): query_kwargs = { 'project': project, } query = request.GET.get('query') if query and uuid_re.match(query): # Forward to event if it exists try: group_id = EventMapping.objects.filter( project=project, event_id=query ).values('group', flat=True)[0] except EventMapping.DoesNotExist: pass else: return HttpResponseRedirect(reverse('sentry-group', kwargs={ 'project_id': project.slug, 'team_slug': project.team.slug, 'group_id': group_id, })) elif query: query_kwargs['query'] = query if request.GET.get('status'): query_kwargs['status'] = int(request.GET['status']) if request.user.is_authenticated() and request.GET.get('bookmarks'): query_kwargs['bookmarked_by'] = 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 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', request.GET.get('c')) if cursor: query_kwargs['cursor'] = cursor results = app.search.query(**query_kwargs) return { 'event_list': results, 'date_from': date_from, 'date_to': date_to, 'today': today, 'sort': sort_by, 'date_type': date_filter, }
def get(self, request, project_id): project = Project.objects.get( id=project_id, ) assert_perm(project, request.user, request.auth) query_kwargs = { 'project': project, } if request.GET.get('status'): query_kwargs['status'] = int(request.GET['status']) if request.user.is_authenticated() and request.GET.get('bookmarks'): query_kwargs['bookmarked_by'] = 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 # TODO: dates should include timestamps date_from = request.GET.get('since') time_from = request.GET.get('until') date_filter = request.GET.get('date_filter') date_to = request.GET.get('dt') time_to = request.GET.get('tt') 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 - 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 # TODO: proper pagination support cursor = request.GET.get('cursor') if cursor: query_kwargs['cursor'] = cursor results = search.query(**query_kwargs) return Response(serialize(list(results), request.user))
event_list = event_list.filter(time_spent_count__gt=0) elif sort == 'avgtime': event_list = event_list.filter(time_spent_count__gt=0) elif sort.startswith('accel_'): event_list = Group.objects.get_accelerated(event_list, minutes=int(sort.split('_', 1)[1])) date_from = request.GET.get('df') time_from = request.GET.get('tf') date_to = request.GET.get('dt') time_to = request.GET.get('tt') today = datetime.datetime.utcnow() # 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=3) date_to = None if date_from: if not date_to: event_list = event_list.filter(last_seen__gte=date_from) else: event_list = event_list.filter(messagecountbyminute__date__gte=date_from) if date_to: if not date_from: event_list = event_list.filter(last_seen__lte=date_to) else: event_list = event_list.filter(messagecountbyminute__date__lte=date_to)
def _get_group_list(request, project): query_kwargs = { 'project': project, } query = request.GET.get('query') if query: query_kwargs['query'] = query 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 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 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 # HACK(dcramer): this should be removed once the pagination component # is abstracted from the paginator tag try: page = int(request.GET.get('p', 1)) except (ValueError, TypeError): page = 1 query_kwargs['offset'] = (page - 1) * EVENTS_PER_PAGE query_kwargs['limit'] = EVENTS_PER_PAGE + 1 results = app.search.query(**query_kwargs) if len(results) == query_kwargs['limit']: next_page = page + 1 else: next_page = None if page > 1: prev_page = page - 1 else: prev_page = None return { 'event_list': results[:EVENTS_PER_PAGE], 'date_from': date_from, 'date_to': date_to, 'today': today, 'sort': sort_by, 'date_type': date_filter, 'previous_page': prev_page, 'next_page': next_page, }
def get(self, request, project_id): """ List a project's aggregates Return a list of aggregates bound to a project. {method} {path}?id=1&id=2&id=3 A default query of 'is:resolved' is applied. To return results with other statuses send an new query value (i.e. ?query= for all results). Any standard Sentry structured search query can be passed via the ``query`` parameter. """ project = Project.objects.get_from_cache( id=project_id, ) assert_perm(project, request.user, request.auth) query_kwargs = { 'project': project, } if request.GET.get('status'): try: query_kwargs['status'] = STATUS_CHOICES[request.GET['status']] except KeyError: return Response('{"error": "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') time_from = request.GET.get('until') date_filter = request.GET.get('date_filter') date_to = request.GET.get('dt') time_to = request.GET.get('tt') limit = request.GET.get('limit') if limit: try: query_kwargs['limit'] = int(limit) except ValueError: return Response('{"error": "invalid limit"}', status=400) 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 - 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 # 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') if query is not None: query_kwargs.update(parse_query(query, request.user)) cursor_result = search.query(**query_kwargs) context = list(cursor_result) GroupMeta.objects.populate_cache(context) response = Response(serialize(context, request.user)) response['Link'] = ', '.join([ self.build_cursor_link(request, 'previous', cursor_result.prev), self.build_cursor_link(request, 'next', cursor_result.next), ]) return response
def get(self, request, project_id): project = Project.objects.get(id=project_id, ) assert_perm(project, request.user, request.auth) query_kwargs = { 'project': project, } if request.GET.get('status'): query_kwargs['status'] = int(request.GET['status']) if request.user.is_authenticated() and request.GET.get('bookmarks'): query_kwargs['bookmarked_by'] = 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 # TODO: dates should include timestamps date_from = request.GET.get('since') time_from = request.GET.get('until') date_filter = request.GET.get('date_filter') date_to = request.GET.get('dt') time_to = request.GET.get('tt') 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 - 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 # TODO: proper pagination support cursor = request.GET.get('cursor') if cursor: query_kwargs['cursor'] = cursor results = search.query(**query_kwargs) return Response(serialize(list(results), request.user))