def get_new_groups(request, project=None): minutes = int(request.REQUEST.get('minutes', 15)) limit = min(100, int(request.REQUEST.get('limit', 10))) if project: project_dict = {project.id: project} else: project_dict = get_project_list(request.user) cutoff = datetime.timedelta(minutes=minutes) cutoff_dt = timezone.now() - cutoff group_list = list( Group.objects.filter( project__in=project_dict.keys(), status=0, active_at__gte=cutoff_dt, ).order_by('-score')[:limit]) for group in group_list: group._project_cache = project_dict.get(group.project_id) data = to_json(group_list, request) response = HttpResponse(data) response['Content-Type'] = 'application/json' return response
def get_group_trends(request, team=None, project=None): minutes = int(request.REQUEST.get('minutes', 15)) limit = min(100, int(request.REQUEST.get('limit', 10))) if not team and project: project_list = [project] else: project_list = Project.objects.get_for_user(request.user, team=team) project_dict = dict((p.id, p) for p in project_list) base_qs = Group.objects.filter( project__in=project_list, status=0, ) cutoff = datetime.timedelta(minutes=minutes) cutoff_dt = timezone.now() - cutoff group_list = list( base_qs.filter(status=STATUS_UNRESOLVED, last_seen__gte=cutoff_dt).extra(select={ 'sort_value': 'score' }).order_by('-score')[:limit]) for group in group_list: group._project_cache = project_dict.get(group.project_id) data = to_json(group_list, request) response = HttpResponse(data) response['Content-Type'] = 'application/json' return response
def resolve(request, team, project): gid = request.REQUEST.get('gid') if not gid: return HttpResponseForbidden() try: group = Group.objects.get(pk=gid) except Group.DoesNotExist: return HttpResponseForbidden() now = timezone.now() happened = Group.objects.filter( pk=group.pk, ).exclude(status=STATUS_RESOLVED).update( status=STATUS_RESOLVED, resolved_at=now, ) group.status = STATUS_RESOLVED group.resolved_at = now if happened: Activity.objects.create( project=project, group=group, type=Activity.SET_RESOLVED, user=request.user, ) return to_json(group, request)
def poll(request, project): offset = 0 limit = settings.MESSAGES_PER_PAGE view_id = request.GET.get('view_id') if view_id: try: view = View.objects.get_from_cache(pk=view_id) except View.DoesNotExist: return HttpResponseBadRequest() else: view = None response = _get_group_list( request=request, project=project, view=view, ) event_list = response['event_list'] event_list = list(event_list[offset:limit]) data = to_json(event_list, request) response = HttpResponse(data) response['Content-Type'] = 'application/json' return response
def get_resolved_groups(request, team=None, project=None): minutes = int(request.REQUEST.get('minutes', 15)) limit = min(100, int(request.REQUEST.get('limit', 10))) if team: project_list = list(Project.objects.filter(team=team)) elif project: project_list = [project] else: project_list = get_project_list(request.user).values() cutoff = datetime.timedelta(minutes=minutes) cutoff_dt = timezone.now() - cutoff group_list = Group.objects.filter( project__in=project_list, status=STATUS_RESOLVED, resolved_at__gte=cutoff_dt, ).select_related('project').order_by('-score')[:limit] data = to_json(group_list, request) response = HttpResponse(json.dumps(data)) response['Content-Type'] = 'application/json' return response
def get_new_groups(request, project=None): minutes = int(request.REQUEST.get('minutes', 15)) limit = min(100, int(request.REQUEST.get('limit', 10))) if project: project_dict = {project.id: project} else: project_dict = get_project_list(request.user) cutoff = datetime.timedelta(minutes=minutes) cutoff_dt = timezone.now() - cutoff group_list = list(Group.objects.filter( project__in=project_dict.keys(), status=0, active_at__gte=cutoff_dt, ).order_by('-score')[:limit]) for group in group_list: group._project_cache = project_dict.get(group.project_id) data = to_json(group_list, request) response = HttpResponse(data) response['Content-Type'] = 'application/json' return response
def get_group_trends(request, team=None, project=None): minutes = int(request.REQUEST.get('minutes', 15)) limit = min(100, int(request.REQUEST.get('limit', 10))) if not team and project: project_list = [project] else: project_list = Project.objects.get_for_user(request.user, team=team) project_dict = dict((p.id, p) for p in project_list) base_qs = Group.objects.filter( project__in=project_list, status=0, ) cutoff = datetime.timedelta(minutes=minutes) cutoff_dt = timezone.now() - cutoff group_list = list(base_qs.filter( status=STATUS_UNRESOLVED, last_seen__gte=cutoff_dt ).extra(select={'sort_value': 'score'}).order_by('-score')[:limit]) for group in group_list: group._project_cache = project_dict.get(group.project_id) data = to_json(group_list, request) response = HttpResponse(data) response['Content-Type'] = 'application/json' return response
def get_group_trends(request, project=None): minutes = int(request.REQUEST.get('minutes', 15)) limit = min(100, int(request.REQUEST.get('limit', 10))) if project: project_dict = {project.pk: project} else: project_dict = get_project_list(request.user) base_qs = Group.objects.filter( project__in=project_dict.keys(), status=0, ) if has_trending(): group_list = list(Group.objects.get_accelerated(base_qs, minutes=( minutes ))[:limit]) else: cutoff = datetime.timedelta(minutes=minutes) cutoff_dt = timezone.now() - cutoff group_list = list(base_qs.filter( last_seen__gte=cutoff_dt ).order_by('-score')[:limit]) for group in group_list: group._project_cache = project_dict.get(group.project_id) data = to_json(group_list, request) response = HttpResponse(data) response['Content-Type'] = 'application/json' return response
def get_group_trends(request, project=None): minutes = int(request.REQUEST.get('minutes', 15)) limit = min(100, int(request.REQUEST.get('limit', 10))) if project: project_dict = {project.pk: project} else: project_dict = get_project_list(request.user) base_qs = Group.objects.filter( project__in=project_dict.keys(), status=0, ) if has_trending(): group_list = list( Group.objects.get_accelerated(base_qs, minutes=(minutes))[:limit]) else: cutoff = datetime.timedelta(minutes=minutes) cutoff_dt = timezone.now() - cutoff group_list = list( base_qs.filter( last_seen__gte=cutoff_dt).order_by('-score')[:limit]) for group in group_list: group._project_cache = project_dict.get(group.project_id) data = to_json(group_list, request) response = HttpResponse(data) response['Content-Type'] = 'application/json' return response
def get_new_groups(request, team=None, project=None): minutes = int(request.REQUEST.get("minutes", 15)) limit = min(100, int(request.REQUEST.get("limit", 10))) if not team and project: project_list = [project] else: project_list = Project.objects.get_for_user(request.user, team=team) project_dict = dict((p.id, p) for p in project_list) cutoff = datetime.timedelta(minutes=minutes) cutoff_dt = timezone.now() - cutoff group_list = list( Group.objects.filter(project__in=project_dict.keys(), status=STATUS_UNRESOLVED, active_at__gte=cutoff_dt) .extra(select={"sort_value": "score"}) .order_by("-score", "-first_seen")[:limit] ) for group in group_list: group._project_cache = project_dict.get(group.project_id) data = to_json(group_list, request) response = HttpResponse(data) response["Content-Type"] = "application/json" return response
def get_resolved_groups(request, team=None, project=None): minutes = int(request.REQUEST.get('minutes', 15)) limit = min(100, int(request.REQUEST.get('limit', 10))) if not team and project: project_list = [project] else: project_list = Project.objects.get_for_user(request.user, team=team) project_dict = dict((p.id, p) for p in project_list) cutoff = datetime.timedelta(minutes=minutes) cutoff_dt = timezone.now() - cutoff group_list = list(Group.objects.filter( project__in=project_list, status=STATUS_RESOLVED, resolved_at__gte=cutoff_dt, ).order_by('-score')[:limit]) for group in group_list: group._project_cache = project_dict.get(group.project_id) data = to_json(group_list, request) response = HttpResponse(json.dumps(data)) response['Content-Type'] = 'application/json' return response
def get_resolved_groups(request, team=None, project=None): minutes = int(request.REQUEST.get('minutes', 15)) limit = min(100, int(request.REQUEST.get('limit', 10))) if not team and project: project_list = [project] else: project_list = Project.objects.get_for_user(request.user, team=team) project_dict = dict((p.id, p) for p in project_list) cutoff = datetime.timedelta(minutes=minutes) cutoff_dt = timezone.now() - cutoff group_list = list( Group.objects.filter( project__in=project_list, status=STATUS_RESOLVED, resolved_at__gte=cutoff_dt, ).order_by('-score')[:limit]) for group in group_list: group._project_cache = project_dict.get(group.project_id) data = to_json(group_list, request) response = HttpResponse(json.dumps(data)) response['Content-Type'] = 'application/json' return response
def get_new_groups(request, organization, team): minutes = int(request.REQUEST.get('minutes', 15)) limit = min(100, int(request.REQUEST.get('limit', 10))) project_list = Project.objects.get_for_user(team=team, user=request.user) project_dict = dict((p.id, p) for p in project_list) cutoff = timedelta(minutes=minutes) cutoff_dt = timezone.now() - cutoff group_list = list( Group.objects.filter( project__in=project_dict.keys(), status=GroupStatus.UNRESOLVED, active_at__gte=cutoff_dt, ).extra(select={ 'sort_value': 'score' }).order_by('-score', '-first_seen')[:limit]) for group in group_list: group._project_cache = project_dict.get(group.project_id) data = to_json(group_list, request) response = HttpResponse(data) response['Content-Type'] = 'application/json' return response
def get_new_groups(request, team=None, project=None): minutes = int(request.REQUEST.get('minutes', 15)) limit = min(100, int(request.REQUEST.get('limit', 10))) if team: project_dict = dict((p.id, p) for p in Project.objects.filter(team=team)) elif project: project_dict = {project.id: project} else: project_dict = get_project_list(request.user) cutoff = datetime.timedelta(minutes=minutes) cutoff_dt = timezone.now() - cutoff group_list = list(Group.objects.filter( project__in=project_dict.keys(), status=STATUS_UNRESOLVED, active_at__gte=cutoff_dt, ).extra(select={'sort_value': 'score'}).order_by('-score', '-first_seen')[:limit]) for group in group_list: group._project_cache = project_dict.get(group.project_id) data = to_json(group_list, request) response = HttpResponse(data) response['Content-Type'] = 'application/json' return response
def unmute_group(request, project, group_id): try: group = Group.objects.get(pk=group_id) except Group.DoesNotExist: return HttpResponseForbidden() group.update(status=STATUS_UNRESOLVED) return to_json(group, request)
def make_group_private(request, project, group_id): try: group = Group.objects.get(pk=group_id) except Group.DoesNotExist: return HttpResponseForbidden() group.update(is_public=False) return to_json(group, request)
def poll(request, team, project): offset = 0 limit = settings.MESSAGES_PER_PAGE response = _get_group_list(request=request, project=project) event_list = response["event_list"] event_list = list(event_list[offset:limit]) return to_json(event_list, request)
def unresolve_group(request, team, project, group_id): try: group = Group.objects.get(pk=group_id) except Group.DoesNotExist: return HttpResponseForbidden() happened = group.update(status=STATUS_UNRESOLVED) if happened: Activity.objects.create(project=project, group=group, type=Activity.SET_UNRESOLVED, user=request.user) return to_json(group, request)
def make_group_private(request, team, project, group_id): try: group = Group.objects.get(pk=group_id) except Group.DoesNotExist: return HttpResponseForbidden() happened = group.update(is_public=False) if happened: Activity.objects.create(project=project, group=group, type=Activity.SET_PRIVATE, user=request.user) return to_json(group, request)
def poll(request, team, project): offset = 0 limit = EVENTS_PER_PAGE response = _get_group_list( request=request, project=project, ) event_list = response['event_list'] event_list = list(event_list[offset:limit]) return to_json(event_list, request)
def poll(request, organization, project): offset = 0 limit = EVENTS_PER_PAGE group_result = _get_group_list( request=request, project=project, ) event_list = group_result['event_list'] event_list = list(event_list[offset:limit]) data = to_json(event_list, request) links = [ ('previous', str(group_result['prev_cursor'])), ('next', str(group_result['next_cursor'])), ] querystring = u'&'.join( u'{0}={1}'.format(urlquote(k), urlquote(v)) for k, v in request.GET.iteritems() if k != 'cursor' ) base_url = request.build_absolute_uri(request.path) if querystring: base_url = '{0}?{1}'.format(base_url, querystring) else: base_url = base_url + '?' link_values = [] for name, cursor in links: link_values.append(LINK_HEADER.format( uri=base_url, cursor=cursor, name=name, has_results='true' if bool(cursor) else 'false', )) headers = {} if link_values: headers['Link'] = ', '.join(link_values) response = HttpResponse(data) response['Content-Type'] = 'application/json' if link_values: response['Link'] = ', '.join(link_values) return response
def unresolve_group(request, team, project, group_id): try: group = Group.objects.get(pk=group_id) except Group.DoesNotExist: return HttpResponseForbidden() happened = group.update(status=STATUS_UNRESOLVED) if happened: Activity.objects.create( project=project, group=group, type=Activity.SET_UNRESOLVED, user=request.user, ) return to_json(group, request)
def make_group_private(request, team, project, group_id): try: group = Group.objects.get(pk=group_id) except Group.DoesNotExist: return HttpResponseForbidden() happened = group.update(is_public=False) if happened: Activity.objects.create( project=project, group=group, type=Activity.SET_PRIVATE, user=request.user, ) return to_json(group, request)
def poll(request, project): offset = 0 limit = settings.MESSAGES_PER_PAGE response = _get_group_list( request=request, project=project, ) event_list = response['event_list'] event_list = list(event_list[offset:limit]) data = to_json(event_list, request) response = HttpResponse(data) response['Content-Type'] = 'application/json' return response
def make_group_public(request, organization, project, group_id): try: group = Group.objects.get(pk=group_id) except Group.DoesNotExist: return HttpResponseForbidden() happened = group.update(is_public=True) if happened: Activity.objects.create( project=project, group=group, type=Activity.SET_PUBLIC, user=request.user, ) return to_json(group, request)
def bookmark(request, team, project): gid = request.REQUEST.get("gid") if not gid: return HttpResponseForbidden() if not request.user.is_authenticated(): return HttpResponseForbidden() try: group = Group.objects.get(pk=gid) except Group.DoesNotExist: return HttpResponseForbidden() gb, created = GroupBookmark.objects.get_or_create(project=group.project, user=request.user, group=group) if not created: gb.delete() return to_json(group, request)
def resolve(request, project): gid = request.REQUEST.get('gid') if not gid: return HttpResponseForbidden() try: group = Group.objects.get(pk=gid) except Group.DoesNotExist: return HttpResponseForbidden() now = timezone.now() Group.objects.filter(pk=group.pk).update( status=1, resolved_at=now, ) group.status = 1 group.resolved_at = now return to_json(group, request)
def unresolve_group(request, organization, project, group_id): try: group = Group.objects.get(pk=group_id) except Group.DoesNotExist: return HttpResponseForbidden() happened = group.update( status=GroupStatus.UNRESOLVED, active_at=timezone.now(), ) if happened: Activity.objects.create( project=project, group=group, type=Activity.SET_UNRESOLVED, user=request.user, ) return to_json(group, request)
def mute_group(request, team, project, group_id): try: group = Group.objects.get(pk=group_id) except Group.DoesNotExist: return HttpResponseForbidden() happened = group.update( status=STATUS_MUTED, resolved_at=timezone.now(), ) if happened: Activity.objects.create( project=project, group=group, type=Activity.SET_MUTED, user=request.user, ) return to_json(group, request)
def bookmark(request, team, project): gid = request.REQUEST.get('gid') if not gid: return HttpResponseForbidden() if not request.user.is_authenticated(): return HttpResponseForbidden() try: group = Group.objects.get(pk=gid) except Group.DoesNotExist: return HttpResponseForbidden() gb, created = GroupBookmark.objects.get_or_create( project=group.project, user=request.user, group=group, ) if not created: gb.delete() return to_json(group, request)
def get_resolved_groups(request, project=None): minutes = int(request.REQUEST.get('minutes', 15)) limit = min(100, int(request.REQUEST.get('limit', 10))) if project: project_list = [project] else: project_list = get_project_list(request.user).values() cutoff = datetime.timedelta(minutes=minutes) cutoff_dt = timezone.now() - cutoff group_list = Group.objects.filter( project__in=project_list, status=1, resolved_at__gte=cutoff_dt, ).select_related('project').order_by('-score')[:limit] data = to_json(group_list, request) response = HttpResponse(json.dumps(data)) response['Content-Type'] = 'application/json' return response