Beispiel #1
0
    def testUseLogging(self):
        Message.objects.all().delete()
        GroupedMessage.objects.all().delete()
        
        request = RF.get("/", REMOTE_ADDR="127.0.0.1:8000")

        try:
            Message.objects.get(id=999999999)
        except Message.DoesNotExist, exc:
            GroupedMessage.handle_exception(request=request, sender=self)
Beispiel #2
0
def index(request):
    filters = []
    for filter_ in get_filters():
        filters.append(filter_(request))
    
    try:
        page = int(request.GET.get('p', 1))
    except (TypeError, ValueError):
        page = 1

    query = request.GET.get('content')
    is_search = query

    if is_search:
        message_list = get_search_query_set(query)
    else:
        message_list = GroupedMessage.objects.extra(
            select={
                'score': GroupedMessage.get_score_clause(),
            }
        )
        if query:
            # You really shouldnt be doing this
            message_list = message_list.filter(
                Q(view__icontains=query) \
                | Q(message__icontains=query) \
                | Q(traceback__icontains=query)
            )

    sort = request.GET.get('sort')
    if sort == 'date':
        message_list = message_list.order_by('-last_seen')
    elif sort == 'new':
        message_list = message_list.order_by('-first_seen')
    else:
        sort = 'priority'
        if not is_search:
            message_list = message_list.order_by('-score', '-last_seen')
    
    any_filter = False
    for filter_ in filters:
        if not filter_.is_set():
            continue
        any_filter = True
        message_list = filter_.get_query_set(message_list)
    
    today = datetime.datetime.now()

    has_realtime = page == 1
    
    return render_to_response('sentry/index.html', {
        'has_realtime': has_realtime,
        'message_list': message_list,
        'today': today,
        'query': query,
        'sort': sort,
        'any_filter': any_filter,
        'request': request,
        'filters': filters,
    })
Beispiel #3
0
def index(request):
    filters = []
    for filter_ in get_filters():
        filters.append(filter_(request))
    
    try:
        page = int(request.GET.get('p', 1))
    except (TypeError, ValueError):
        page = 1

    # this only works in postgres
    message_list = GroupedMessage.objects.extra(
        select={
            'score': GroupedMessage.get_score_clause(),
        }
    ).order_by('-score', '-last_seen').distinct()
    
    any_filter = False
    for filter_ in filters:
        if not filter_.is_set():
            continue
        any_filter = True
        message_list = filter_.get_query_set(message_list)
    
    today = datetime.datetime.now()

    if not any_filter and page == 1:
        realtime = True
    else:
        realtime = False
    
    return render_to_response('sentry/index.html', locals())
Beispiel #4
0
def index(request):
    filters = []
    for filter_ in get_filters():
        filters.append(filter_(request))
    
    try:
        page = int(request.GET.get('p', 1))
    except (TypeError, ValueError):
        page = 1

    message_list = GroupedMessage.objects.extra(
        select={
            'score': GroupedMessage.get_score_clause(),
        }
    )

    sort = request.GET.get('sort')
    if sort == 'date':
        message_list = message_list.order_by('-last_seen')
    elif sort == 'new':
        message_list = message_list.order_by('-first_seen')
    else:
        sort = 'priority'
        message_list = message_list.order_by('-score', '-last_seen')
    
    # Filters only apply if we're not searching
    any_filter = False
    for filter_ in filters:
        if not filter_.is_set():
            continue
        any_filter = True
        message_list = filter_.get_query_set(message_list)
    
    today = datetime.datetime.now()

    has_realtime = page == 1
    
    return render_to_response('sentry/index.html', {
        'has_realtime': has_realtime,
        'message_list': message_list,
        'today': today,
        'sort': sort,
        'any_filter': any_filter,
        'request': request,
        'filters': filters,
    })
Beispiel #5
0
def index(request):
    filters = []
    for filter_ in get_filters():
        filters.append(filter_(request))

    try:
        page = int(request.GET.get('p', 1))
    except (TypeError, ValueError):
        page = 1

    message_list = GroupedMessage.objects.extra(
        select={
            'score': GroupedMessage.get_score_clause(),
        })

    sort = request.GET.get('sort')
    if sort == 'date':
        message_list = message_list.order_by('-last_seen')
    elif sort == 'new':
        message_list = message_list.order_by('-first_seen')
    else:
        sort = 'priority'
        message_list = message_list.order_by('-score', '-last_seen')

    # Filters only apply if we're not searching
    any_filter = False
    for filter_ in filters:
        if not filter_.is_set():
            continue
        any_filter = True
        message_list = filter_.get_query_set(message_list)

    today = datetime.datetime.now()

    has_realtime = page == 1

    return render_to_response(
        'sentry/index.html', {
            'has_realtime': has_realtime,
            'message_list': message_list,
            'today': today,
            'sort': sort,
            'any_filter': any_filter,
            'request': request,
            'filters': filters,
        })
Beispiel #6
0
def ajax_handler(request):
    op = request.REQUEST.get('op')
    if op == 'poll':
        message_list = GroupedMessage.objects.extra(
            select={
                'score': GroupedMessage.get_score_clause(),
            }
        ).order_by('-score', '-last_seen')
        
        data = [
            (m.pk, {
                'html': render_to_string('sentry/partial/_group.html', {'group': m, 'priority': p}),
                'count': m.times_seen,
                'priority': p,
            }) for m, p in with_priority(message_list[0:15])]

    elif op == 'resolve':
        gid = request.REQUEST.get('gid')
        if not gid:
            return HttpResponseForbidden()
        try:
            group = GroupedMessage.objects.get(pk=gid)
        except GroupedMessage.DoesNotExist:
            return HttpResponseForbidden()
        
        GroupedMessage.objects.filter(pk=group.pk).update(status=1)
        group.status = 1
        
        if not request.is_ajax():
            return HttpResponseRedirect(request.META['HTTP_REFERER'])
        
        data = [
            (m.pk, {
                'html': render_to_string('sentry/partial/_group.html', {'group': m}),
                'count': m.times_seen,
            }) for m in [group]]
        
    response = HttpResponse(simplejson.dumps(data))
    response['Content-Type'] = 'application/json'
    return response
Beispiel #7
0
def index(request):
    filters = []
    for filter_ in get_filters():
        filters.append(filter_(request))
    
    try:
        page = int(request.GET.get('p', 1))
    except (TypeError, ValueError):
        page = 1

    # this only works in postgres
    message_list = GroupedMessage.objects.extra(
        select={
            'score': GroupedMessage.get_score_clause(),
        }
    )

    sort = request.GET.get('sort')
    if sort == 'date':
        message_list = message_list.order_by('-last_seen')
    elif sort == 'new':
        message_list = message_list.order_by('-first_seen')
    else:
        sort = 'priority'
        message_list = message_list.order_by('-score', '-last_seen')

    
    any_filter = False
    for filter_ in filters:
        if not filter_.is_set():
            continue
        any_filter = True
        message_list = filter_.get_query_set(message_list)
    
    today = datetime.datetime.now()

    has_realtime = page == 1
    
    return render_to_response('sentry/index.html', locals())
Beispiel #8
0
def index(request):
    filters = []
    for filter_ in get_filters():
        filters.append(filter_(request))

    try:
        page = int(request.GET.get("p", 1))
    except (TypeError, ValueError):
        page = 1

    # this only works in postgres
    message_list = GroupedMessage.objects.extra(select={"score": GroupedMessage.get_score_clause()})

    sort = request.GET.get("sort")
    if sort == "date":
        message_list = message_list.order_by("-last_seen")
    elif sort == "new":
        message_list = message_list.order_by("-first_seen")
    else:
        sort = "priority"
        message_list = message_list.order_by("-score", "-last_seen")

    any_filter = False

    query = Q()
    for filter_ in filters:
        if not filter_.is_set():
            continue
        any_filter = True
        query &= filter_._get_query()
    message_list = message_list.filter(query).distinct()

    today = datetime.datetime.now()

    has_realtime = page == 1
    config = conf
    return locals()
Beispiel #9
0
def index(request):
    filters = []
    for filter_ in get_filters():
        filters.append(filter_(request))

    try:
        page = int(request.GET.get('p', 1))
    except (TypeError, ValueError):
        page = 1

    # this only works in postgres
    message_list = GroupedMessage.objects.extra(
        select={
            'score': GroupedMessage.get_score_clause(),
        })

    sort = request.GET.get('sort')
    if sort == 'date':
        message_list = message_list.order_by('-last_seen')
    elif sort == 'new':
        message_list = message_list.order_by('-first_seen')
    else:
        sort = 'priority'
        message_list = message_list.order_by('-score', '-last_seen')

    any_filter = False
    for filter_ in filters:
        if not filter_.is_set():
            continue
        any_filter = True
        message_list = filter_.get_query_set(message_list)

    today = datetime.datetime.now()

    has_realtime = page == 1

    return render_to_response('sentry/index.html', locals())
Beispiel #10
0
def ajax_handler(request):
    op = request.REQUEST.get("op")

    if op == "poll":
        filters = []
        for filter_ in get_filters():
            filters.append(filter_(request))

        message_list = GroupedMessage.objects.extra(select={"score": GroupedMessage.get_score_clause()})

        sort = request.GET.get("sort")
        if sort == "date":
            message_list = message_list.order_by("-last_seen")
        elif sort == "new":
            message_list = message_list.order_by("-first_seen")
        else:
            sort = "priority"
            message_list = message_list.order_by("-score", "-last_seen")

        query = Q()
        for filter_ in filters:
            if not filter_.is_set():
                continue
            any_filter = True
            query &= filter_._get_query()
        message_list = message_list.filter(query).distinct()

        data = [
            (
                m.pk,
                {
                    "html": render_to_string(
                        "sentry/partial/_group.html", {"group": m, "priority": p, "request": request}
                    ),
                    "count": m.times_seen,
                    "priority": p,
                },
            )
            for m, p in with_priority(message_list[0:15])
        ]

    elif op == "resolve":
        gid = request.REQUEST.get("gid")
        if not gid:
            return HttpResponseForbidden()
        try:
            group = GroupedMessage.objects.get(pk=gid)
        except GroupedMessage.DoesNotExist:
            return HttpResponseForbidden()

        GroupedMessage.objects.filter(pk=group.pk).update(status=1)
        group.status = 1

        if not request.is_ajax():
            return HttpResponseRedirect(request.META["HTTP_REFERER"])

        data = [
            (
                m.pk,
                {
                    "html": render_to_string("sentry/partial/_group.html", {"group": m, "request": request}),
                    "count": m.times_seen,
                },
            )
            for m in [group]
        ]
    else:
        return HttpResponseBadRequest()

    response = HttpResponse(simplejson.dumps(data))
    response["Content-Type"] = "application/json"
    return response
Beispiel #11
0
def ajax_handler(request):
    op = request.REQUEST.get('op')

    if op == 'poll':
        filters = []
        for filter_ in get_filters():
            filters.append(filter_(request))

        message_list = GroupedMessage.objects.extra(
            select={
                'score': GroupedMessage.get_score_clause(),
            })

        sort = request.GET.get('sort')
        if sort == 'date':
            message_list = message_list.order_by('-last_seen')
        elif sort == 'new':
            message_list = message_list.order_by('-first_seen')
        else:
            sort = 'priority'
            message_list = message_list.order_by('-score', '-last_seen')

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

        data = [(m.pk, {
            'html':
            render_to_string('sentry/partial/_group.html', {
                'group': m,
                'priority': p
            }),
            'count':
            m.times_seen,
            'priority':
            p,
        }) for m, p in with_priority(message_list[0:15])]

    elif op == 'resolve':
        gid = request.REQUEST.get('gid')
        if not gid:
            return HttpResponseForbidden()
        try:
            group = GroupedMessage.objects.get(pk=gid)
        except GroupedMessage.DoesNotExist:
            return HttpResponseForbidden()

        GroupedMessage.objects.filter(pk=group.pk).update(status=1)
        group.status = 1

        if not request.is_ajax():
            return HttpResponseRedirect(request.META['HTTP_REFERER'])

        data = [(m.pk, {
            'html':
            render_to_string('sentry/partial/_group.html', {'group': m}),
            'count':
            m.times_seen,
        }) for m in [group]]
    else:
        return HttpResponseBadRequest()

    response = HttpResponse(simplejson.dumps(data))
    response['Content-Type'] = 'application/json'
    return response
Beispiel #12
0
     self.assertEquals(last.logger, 'root')
     self.assertEquals(last.class_name, 'DoesNotExist')
     self.assertEquals(last.level, logging.ERROR)
     self.assertEquals(last.message, smart_unicode(exc))
     
     settings.USE_LOGGING = True
     
     logger = logging.getLogger('sentry')
     for h in logger.handlers:
         logger.removeHandler(h)
     logger.addHandler(logging.StreamHandler())
     
     try:
         Message.objects.get(id=999999999)
     except Message.DoesNotExist, exc:
         GroupedMessage.handle_exception(request=request, sender=self)
     else:
         self.fail('Expected an exception.')
     
     cur = (Message.objects.count(), GroupedMessage.objects.count())
     self.assertEquals(cur, (1, 1), 'Assumed logs failed to save. %s' % (cur,))
     
     settings.USE_LOGGING = False
 
 def testThrashing(self):
     settings.THRASHING_LIMIT = 10
     settings.THRASHING_TIMEOUT = 60
     
     Message.objects.all().delete()
     GroupedMessage.objects.all().delete()
     
Beispiel #13
0
def index(request):
    filters = []
    for filter_ in get_filters():
        filters.append(filter_(request))

    try:
        page = int(request.GET.get('p', 1))
    except (TypeError, ValueError):
        page = 1

    query = request.GET.get('content')
    is_search = query

    if is_search:
        if uuid_re.match(query):
            # Forward to message if it exists
            try:
                message = Message.objects.get(message_id=query)
            except Message.DoesNotExist:
                pass
            else:
                return HttpResponseRedirect(message.get_absolute_url())

        message_list = get_search_query_set(query)
    else:
        message_list = GroupedMessage.objects.extra(
            select={
                'score': GroupedMessage.get_score_clause(),
            }
        )
        if query:
            # You really shouldnt be doing this
            message_list = message_list.filter(
                Q(view__icontains=query) \
                | Q(message__icontains=query) \
                | Q(traceback__icontains=query)
            )

    sort = request.GET.get('sort')
    if sort == 'date':
        message_list = message_list.order_by('-last_seen')
    elif sort == 'new':
        message_list = message_list.order_by('-first_seen')
    else:
        sort = 'priority'
        if not is_search:
            message_list = message_list.order_by('-score', '-last_seen')

    any_filter = False
    for filter_ in filters:
        if not filter_.is_set():
            continue
        any_filter = True
        message_list = filter_.get_query_set(message_list)

    today = timezone.now()

    has_realtime = page == 1

    return render_to_response('sentry/index.html', {
        'has_realtime': has_realtime,
        'message_list': message_list,
        'today': today,
        'query': query,
        'sort': sort,
        'any_filter': any_filter,
        'request': request,
        'filters': filters,
    })
Beispiel #14
0
def ajax_handler(request):
    op = request.REQUEST.get('op')

    if op == 'notification':
        return render_to_response('sentry/partial/_notification.html', request.GET)
    elif op == 'poll':
        filters = []
        for filter_ in get_filters():
            filters.append(filter_(request))

        query = request.GET.get('content')
        is_search = query

        if is_search:
            message_list = get_search_query_set(query)
        else:
            message_list = GroupedMessage.objects.extra(
                select={
                    'score': GroupedMessage.get_score_clause(),
                }
            )
            if query:
                # You really shouldnt be doing this
                message_list = message_list.filter(
                    Q(view__icontains=query) \
                    | Q(message__icontains=query) \
                    | Q(traceback__icontains=query)
                )

        sort = request.GET.get('sort')
        if sort == 'date':
            message_list = message_list.order_by('-last_seen')
        elif sort == 'new':
            message_list = message_list.order_by('-first_seen')
        else:
            sort = 'priority'
            if not is_search:
                message_list = message_list.order_by('-score', '-last_seen')

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

        data = [
            (m.pk, {
                'html': render_to_string('sentry/partial/_group.html', {
                    'group': m,
                    'priority': p,
                    'request': request,
                }).strip(),
                'title': m.view or m.message_top(),
                'message': m.error(),
                'level': m.get_level_display(),
                'logger': m.logger,
                'count': m.times_seen,
                'priority': p,
            }) for m, p in with_priority(message_list[0:15])]

    elif op == 'resolve':
        gid = request.REQUEST.get('gid')
        if not gid:
            return HttpResponseForbidden()
        try:
            group = GroupedMessage.objects.get(pk=gid)
        except GroupedMessage.DoesNotExist:
            return HttpResponseForbidden()

        GroupedMessage.objects.filter(pk=group.pk).update(status=1)
        group.status = 1

        if not request.is_ajax():
            return HttpResponseRedirect(request.META['HTTP_REFERER'])

        data = [
            (m.pk, {
                'html': render_to_string('sentry/partial/_group.html', {
                    'group': m,
                    'request': request,
                }).strip(),
                'count': m.times_seen,
            }) for m in [group]]
    else:
        return HttpResponseBadRequest()

    response = HttpResponse(json.dumps(data))
    response['Content-Type'] = 'application/json'
    return response
Beispiel #15
0
def index(request):
    filters = []
    for filter_ in get_filters():
        filters.append(filter_(request))

    try:
        page = int(request.GET.get("p", 1))
    except (TypeError, ValueError):
        page = 1

    query = request.GET.get("content")
    is_search = query

    if is_search:
        if uuid_re.match(query):
            # Forward to message if it exists
            try:
                message = Message.objects.get(message_id=query)
            except Message.DoesNotExist:
                pass
            else:
                return HttpResponseRedirect(message.get_absolute_url())

        message_list = get_search_query_set(query)
    else:
        message_list = GroupedMessage.objects.extra(select={"score": GroupedMessage.get_score_clause()})
        if query:
            # You really shouldnt be doing this
            message_list = message_list.filter(
                Q(view__icontains=query) | Q(message__icontains=query) | Q(traceback__icontains=query)
            )

    sort = request.GET.get("sort")
    if sort == "date":
        message_list = message_list.order_by("-last_seen")
    elif sort == "new":
        message_list = message_list.order_by("-first_seen")
    else:
        sort = "priority"
        if not is_search:
            message_list = message_list.order_by("-score", "-last_seen")

    any_filter = False
    for filter_ in filters:
        if not filter_.is_set():
            continue
        any_filter = True
        message_list = filter_.get_query_set(message_list)

    today = datetime.datetime.now()

    has_realtime = page == 1

    return render_to_response(
        "sentry/index.html",
        {
            "has_realtime": has_realtime,
            "message_list": message_list,
            "today": today,
            "query": query,
            "sort": sort,
            "any_filter": any_filter,
            "request": request,
            "filters": filters,
        },
    )
Beispiel #16
0
def ajax_handler(request):
    op = request.REQUEST.get("op")

    if op == "notification":
        return render_to_response("sentry/partial/_notification.html", request.GET)
    elif op == "poll":
        filters = []
        for filter_ in get_filters():
            filters.append(filter_(request))

        query = request.GET.get("content")
        is_search = query

        if is_search:
            message_list = get_search_query_set(query)
        else:
            message_list = GroupedMessage.objects.extra(select={"score": GroupedMessage.get_score_clause()})
            if query:
                # You really shouldnt be doing this
                message_list = message_list.filter(
                    Q(view__icontains=query) | Q(message__icontains=query) | Q(traceback__icontains=query)
                )

        sort = request.GET.get("sort")
        if sort == "date":
            message_list = message_list.order_by("-last_seen")
        elif sort == "new":
            message_list = message_list.order_by("-first_seen")
        else:
            sort = "priority"
            if not is_search:
                message_list = message_list.order_by("-score", "-last_seen")

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

        data = [
            (
                m.pk,
                {
                    "html": render_to_string(
                        "sentry/partial/_group.html", {"group": m, "priority": p, "request": request}
                    ).strip(),
                    "title": m.view or m.message_top(),
                    "message": m.error(),
                    "level": m.get_level_display(),
                    "logger": m.logger,
                    "count": m.times_seen,
                    "priority": p,
                },
            )
            for m, p in with_priority(message_list[0:15])
        ]

    elif op == "resolve":
        gid = request.REQUEST.get("gid")
        if not gid:
            return HttpResponseForbidden()
        try:
            group = GroupedMessage.objects.get(pk=gid)
        except GroupedMessage.DoesNotExist:
            return HttpResponseForbidden()

        GroupedMessage.objects.filter(pk=group.pk).update(status=1)
        group.status = 1

        if not request.is_ajax():
            return HttpResponseRedirect(request.META["HTTP_REFERER"])

        data = [
            (
                m.pk,
                {
                    "html": render_to_string("sentry/partial/_group.html", {"group": m, "request": request}).strip(),
                    "count": m.times_seen,
                },
            )
            for m in [group]
        ]
    else:
        return HttpResponseBadRequest()

    response = HttpResponse(simplejson.dumps(data))
    response["Content-Type"] = "application/json"
    return response
Beispiel #17
0
def ajax_handler(request):
    op = request.REQUEST.get('op')

    if op == 'notification':
        return render_to_response('sentry/partial/_notification.html',
                                  request.GET,
                                  context_instance=RequestContext(request))
    elif op == 'poll':
        filters = []
        for filter_ in get_filters():
            filters.append(filter_(request))

        query = request.GET.get('content')
        is_search = query

        if is_search:
            message_list = get_search_query_set(query)
        else:
            message_list = GroupedMessage.objects.extra(
                select={
                    'score': GroupedMessage.get_score_clause(),
                }
            )
            if query:
                # You really shouldnt be doing this
                message_list = message_list.filter(
                    Q(view__icontains=query) \
                    | Q(message__icontains=query) \
                    | Q(traceback__icontains=query)
                )
        
        sort = request.GET.get('sort')
        if sort == 'date':
            message_list = message_list.order_by('-last_seen')
        elif sort == 'new':
            message_list = message_list.order_by('-first_seen')
        else:
            sort = 'priority'
            if not is_search:
                message_list = message_list.order_by('-score', '-last_seen')

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

        data = [
            (m.pk, {
                'html': render_to_string('sentry/partial/_group.html', {
                    'group': m,
                    'priority': p,
                    'request': request,
                }).strip(),
                'title': m.view or m.message_top(),
                'message': m.error(),
                'level': m.get_level_display(),
                'logger': m.logger,
                'count': m.times_seen,
                'priority': p,
            }) for m, p in with_priority(message_list[0:15])]

    elif op == 'resolve':
        gid = request.REQUEST.get('gid')
        if not gid:
            return HttpResponseForbidden()
        try:
            group = GroupedMessage.objects.get(pk=gid)
        except GroupedMessage.DoesNotExist:
            return HttpResponseForbidden()

        GroupedMessage.objects.filter(pk=group.pk).update(status=1)
        group.status = 1

        if not request.is_ajax():
            return HttpResponseRedirect(request.META['HTTP_REFERER'])

        data = [
            (m.pk, {
                'html': render_to_string('sentry/partial/_group.html', {
                    'group': m,
                    'request': request,
                }).strip(),
                'count': m.times_seen,
            }) for m in [group]]
    else:
        return HttpResponseBadRequest()

    response = HttpResponse(simplejson.dumps(data))
    response['Content-Type'] = 'application/json'
    return response
Beispiel #18
0
def ajax_handler(request):
    op = request.REQUEST.get('op')

    if op == 'poll':
        filters = []
        for filter_ in get_filters():
            filters.append(filter_(request))

        message_list = GroupedMessage.objects.extra(
            select={
                'score': GroupedMessage.get_score_clause(),
            }
        )
        
        sort = request.GET.get('sort')
        if sort == 'date':
            message_list = message_list.order_by('-last_seen')
        elif sort == 'new':
            message_list = message_list.order_by('-first_seen')
        else:
            sort = 'priority'
            message_list = message_list.order_by('-score', '-last_seen')
        
        for filter_ in filters:
            if not filter_.is_set():
                continue
            message_list = filter_.get_query_set(message_list)
        
        data = [
            (m.pk, {
                'html': render_to_string('sentry/partial/_group.html', {
                    'group': m,
                    'priority': p,
                    'request': request,
                }),
                'count': m.times_seen,
                'priority': p,
            }) for m, p in with_priority(message_list[0:15])]

    elif op == 'resolve':
        gid = request.REQUEST.get('gid')
        if not gid:
            return HttpResponseForbidden()
        try:
            group = GroupedMessage.objects.get(pk=gid)
        except GroupedMessage.DoesNotExist:
            return HttpResponseForbidden()
        
        GroupedMessage.objects.filter(pk=group.pk).update(status=1)
        group.status = 1
        
        if not request.is_ajax():
            return HttpResponseRedirect(request.META['HTTP_REFERER'])
        
        data = [
            (m.pk, {
                'html': render_to_string('sentry/partial/_group.html', {
                    'group': m,
                    'request': request,
                }),
                'count': m.times_seen,
            }) for m in [group]]
    else:
        return HttpResponseBadRequest()
        
    response = HttpResponse(simplejson.dumps(data))
    response['Content-Type'] = 'application/json'
    return response