示例#1
0
文件: groups.py 项目: jmacul2/sentry
def group_list(request, project, view_id=None):
    try:
        page = int(request.GET.get('p', 1))
    except (TypeError, ValueError):
        page = 1

    if view_id:
        try:
            view = View.objects.get_from_cache(pk=view_id)
        except View.DoesNotExist:
            return HttpResponseRedirect(reverse('sentry', args=[project.pk]))
    else:
        view = None

    filters, event_list = _get_group_list(
        request=request,
        project=project,
        view=view,
    )

    # XXX: this is duplicate in _get_group_list
    sort = request.GET.get('sort')
    if sort not in SORT_OPTIONS:
        sort = settings.DEFAULT_SORT_OPTION
    sort_label = SORT_OPTIONS[sort]

    since = request.GET.get('since')
    if since not in DATE_OPTIONS:
        since = settings.DEFAULT_DATE_OPTION
    since_label = DATE_OPTIONS[since]

    today = datetime.datetime.utcnow()

    has_realtime = page == 1

    return render_to_response('sentry/groups/group_list.html', {
        'project': project,

        'has_realtime': has_realtime,
        'event_list': event_list,
        'today': today,
        'sort': sort,
        'sort_label': sort_label,
        'since': since,
        'since_label': since_label,
        'filters': filters,
        'view': view,
        'SORT_OPTIONS': SORT_OPTIONS,
        'DATE_OPTIONS': DATE_OPTIONS,
        'HAS_TRENDING': has_trending(),
        'PAGE': 'dashboard',
    }, request)
示例#2
0
def _get_group_list(request, project, view=None):
    filters = []
    for cls in Filter.handlers.filter(Group):
        filters.append(cls(request))

    event_list = Group.objects
    if 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)

    if view:
        event_list = event_list.filter(views=view)

    for filter_ in filters:
        if not filter_.is_set():
            continue
        event_list = filter_.get_query_set(event_list)

    sort = request.GET.get('sort')
    if sort not in SORT_OPTIONS:
        sort = DEFAULT_SORT_OPTION

    if sort == 'date':
        event_list = event_list.order_by('-last_seen')
    elif sort == 'new':
        event_list = event_list.order_by('-first_seen')
    elif sort == 'freq':
        event_list = event_list.order_by('-times_seen')
    elif sort == 'tottime':
        event_list = event_list.filter(time_spent_count__gt=0)\
                                .order_by('-time_spent_total')
    elif sort == 'avgtime':
        event_list = event_list.filter(time_spent_count__gt=0)\
                               .extra(select={'avg_time_spent': 'time_spent_total / time_spent_count'})\
                               .order_by('-avg_time_spent')
    elif has_trending() and sort and sort.startswith('accel_'):
        event_list = Group.objects.get_accelerated(event_list,
                                                   minutes=int(
                                                       sort.split('_', 1)[1]))
    elif sort == 'priority':
        sort = 'priority'
        event_list = event_list.order_by('-score', '-last_seen')
    else:
        raise NotImplementedError('Sort not implemented: %r' % sort)

    return filters, event_list
示例#3
0
文件: groups.py 项目: twoolie/sentry
def _get_group_list(request, project, view=None):
    filters = []
    for cls in Filter.objects.filter(Group):
        filters.append(cls(request))

    event_list = Group.objects
    if 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)

    if view:
        event_list = event_list.filter(views=view)

    for filter_ in filters:
        if not filter_.is_set():
            continue
        event_list = filter_.get_query_set(event_list)

    sort = request.GET.get('sort')
    if sort not in SORT_OPTIONS:
        sort = DEFAULT_SORT_OPTION

    if sort == 'date':
        event_list = event_list.order_by('-last_seen')
    elif sort == 'new':
        event_list = event_list.order_by('-first_seen')
    elif sort == 'freq':
        event_list = event_list.order_by('-times_seen')
    elif sort == 'tottime':
        event_list = event_list.filter(time_spent_count__gt=0)\
                                .order_by('-time_spent_total')
    elif sort == 'avgtime':
        event_list = event_list.filter(time_spent_count__gt=0)\
                               .extra(select={'avg_time_spent': 'time_spent_total / time_spent_count'})\
                               .order_by('-avg_time_spent')
    elif has_trending() and sort and sort.startswith('accel_'):
        event_list = Group.objects.get_accelerated(event_list, minutes=int(sort.split('_', 1)[1]))
    elif sort == 'priority':
        sort = 'priority'
        event_list = event_list.order_by('-score', '-last_seen')
    else:
        raise NotImplementedError('Sort not implemented: %r' % sort)

    return filters, event_list
示例#4
0
def group_list(request, project, view_id=None):
    try:
        page = int(request.GET.get('p', 1))
    except (TypeError, ValueError):
        page = 1

    if view_id:
        try:
            view = View.objects.get(pk=view_id)
        except View.DoesNotExist:
            return HttpResponseRedirect(reverse('sentry', args=[project.pk]))
    else:
        view = None

    filters, event_list = _get_group_list(
        request=request,
        project=project,
        view=view,
    )

    # XXX: this is duplicate in _get_group_list
    sort = request.GET.get('sort')
    if sort not in SORT_OPTIONS:
        sort = DEFAULT_SORT_OPTION
    sort_label = _get_sort_label(sort)

    today = timezone.now()

    has_realtime = page == 1

    return render_to_response(
        'sentry/groups/group_list.html', {
            'project': project,
            'has_realtime': has_realtime,
            'event_list': event_list,
            'today': today,
            'sort': sort,
            'sort_label': sort_label,
            'filters': filters,
            'view': view,
            'HAS_TRENDING': has_trending(),
        }, request)
示例#5
0
def group_list(request, project, view_id=None):
    try:
        page = int(request.GET.get('p', 1))
    except (TypeError, ValueError):
        page = 1

    if view_id:
        try:
            view = View.objects.get(pk=view_id)
        except View.DoesNotExist:
            return HttpResponseRedirect(reverse('sentry', args=[project.pk]))
    else:
        view = None

    filters, event_list = _get_group_list(
        request=request,
        project=project,
        view=view,
    )

    # XXX: this is duplicate in _get_group_list
    sort = request.GET.get('sort')
    if sort not in SORT_OPTIONS:
        sort = DEFAULT_SORT_OPTION
    sort_label = _get_sort_label(sort)

    today = timezone.now()

    has_realtime = page == 1

    return render_to_response('sentry/groups/group_list.html', {
        'project': project,
        'has_realtime': has_realtime,
        'event_list': event_list,
        'today': today,
        'sort': sort,
        'sort_label': sort_label,
        'filters': filters,
        'view': view,
        'HAS_TRENDING': has_trending(),
    }, request)
示例#6
0
文件: groups.py 项目: jmacul2/sentry
def _get_group_list(request, project, view=None):
    filters = []
    for cls in Filter.objects.filter(Group):
        filters.append(cls(request))

    event_list = Group.objects
    if 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)

    if view:
        event_list = event_list.filter(views=view)

    for filter_ in filters:
        if not filter_.is_set():
            continue
        event_list = filter_.get_query_set(event_list)

    sort = request.GET.get('sort')
    if sort not in SORT_OPTIONS:
        sort = settings.DEFAULT_SORT_OPTION

    if sort.startswith('accel_') and not has_trending():
        sort = settings.DEFAULT_SORT_OPTION

    if not sort.startswith('accel_'):
        since = request.GET.get('since', '')
        if since not in DATE_OPTIONS:
            since = settings.DEFAULT_DATE_OPTION
    else:
        since = None

    engine = get_db_engine('default')
    if engine.startswith('sqlite'):
        sort_clause = SQLITE_SORT_CLAUSES.get(sort)
    elif engine.startswith('mysql'):
        sort_clause = MYSQL_SORT_CLAUSES.get(sort)
    else:
        sort_clause = SORT_CLAUSES.get(sort)

    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(event_list, minutes=int(sort.split('_', 1)[1]))

    if since in DATE_VALUES:
        event_list = event_list.filter(last_seen__gte=datetime.datetime.now() - DATE_VALUES[since])

    if sort_clause:
        event_list = event_list.extra(
            select={'sort_value': sort_clause},
        ).order_by('-sort_value', '-last_seen')
        cursor = request.GET.get('cursor')
        if cursor:
            event_list = event_list.extra(
                where=['%s > %%s' % sort_clause],
                params=[cursor],
            )

    return filters, event_list
示例#7
0
文件: groups.py 项目: dgholz/sentry
        event_list = event_list.filter(views=view)

    for filter_ in filters:
        try:
            if not filter_.is_set():
                continue
            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)

    sort = request.GET.get('sort')
    if sort not in SORT_OPTIONS:
        sort = settings.DEFAULT_SORT_OPTION

    if sort.startswith('accel_') and not has_trending():
        sort = settings.DEFAULT_SORT_OPTION

    if not sort.startswith('accel_'):
        since = request.GET.get('since', '')
        if since not in DATE_OPTIONS:
            since = settings.DEFAULT_DATE_OPTION
    else:
        since = None

    engine = get_db_engine('default')
    if engine.startswith('sqlite'):
        sort_clause = SQLITE_SORT_CLAUSES.get(sort)
    elif engine.startswith('mysql'):
        sort_clause = MYSQL_SORT_CLAUSES.get(sort)
    else: