Returning all historical flips if no parameters are passed

This commit is contained in:
James Kirsop 2020-06-12 17:42:45 +10:00
parent 7d625cb6a6
commit c5c4e0f782

View File

@ -304,6 +304,11 @@ def flips(request, code):
if check.project_id != request.project.id:
return HttpResponseForbidden()
if all(x not in request.GET for x in ('start','end','seconds')):
flips = Flip.objects.select_related("owner").filter(
owner=check, new_status__in=("down","up"),
).order_by("created")
else:
if any(x in request.GET for x in ('start','end')) and 'seconds' in request.GET:
return HttpResponseBadRequest()
@ -317,14 +322,13 @@ def flips(request, code):
if 'seconds' in request.GET:
history_start = datetime.now()-td(seconds=int(request.GET['seconds']))
elif not history_start:
history_start = datetime.now()-td(seconds=3600)
flips = Flip.objects.select_related("owner").filter(
owner=check, new_status__in=("down","up"),
created__gt=history_start,
created__lt=history_end
).order_by("created")
dictStatus = {"up":1,"down":0}
return JsonResponse({"flips": list(map(lambda x: {'timestamp':x.created,'up':dictStatus[x.new_status]}, flips))})