aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/views.py
diff options
context:
space:
mode:
authorSean Smith <ssmith@iol.unh.edu>2020-08-11 10:41:27 -0400
committerSawyer Bergeron <sbergeron@iol.unh.edu>2020-11-09 21:52:23 +0000
commit986f474e540669fd9fb72810b3f31fa3f4c3e97a (patch)
tree7c3c27720c962577b88f7cccafac3f3b948ddab9 /src/api/views.py
parenta45a7552146801154f2267fe7e8fae443605bfe3 (diff)
Analytics changes
Signed-off-by: Sean Smith <ssmith@iol.unh.edu> Change-Id: Iaea350b3042f9c866939a9d1a79bdef1e165c1a7 Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
Diffstat (limited to 'src/api/views.py')
-rw-r--r--src/api/views.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/api/views.py b/src/api/views.py
index 75a0db3..2e5f33f 100644
--- a/src/api/views.py
+++ b/src/api/views.py
@@ -18,6 +18,7 @@ from django.http.response import JsonResponse, HttpResponse
from rest_framework import viewsets
from rest_framework.authtoken.models import Token
from django.views.decorators.csrf import csrf_exempt
+from django.core.exceptions import ObjectDoesNotExist
from api.serializers.booking_serializer import BookingSerializer
from api.serializers.old_serializers import UserSerializer
@@ -26,6 +27,8 @@ from account.models import UserProfile
from booking.models import Booking
from api.models import LabManagerTracker, get_task
from notifier.manager import NotificationHandler
+from analytics.models import ActiveVPNUser
+import json
"""
API views.
@@ -176,6 +179,23 @@ def current_jobs(request, lab_name=""):
return JsonResponse(lab_manager.get_current_jobs(), safe=False)
+@csrf_exempt
+def analytics_job(request, lab_name=""):
+ """ returns all jobs with type booking"""
+ lab_token = request.META.get('HTTP_AUTH_TOKEN')
+ lab_manager = LabManagerTracker.get(lab_name, lab_token)
+ if request.method == "GET":
+ return JsonResponse(lab_manager.get_analytics_job(), safe=False)
+ if request.method == "POST":
+ users = json.loads(request.body.decode('utf-8'))['active_users']
+ try:
+ ActiveVPNUser.create(lab_name, users)
+ except ObjectDoesNotExist:
+ return JsonResponse('Lab does not exist!', safe=False)
+ return HttpResponse(status=200)
+ return HttpResponse(status=405)
+
+
def lab_downtime(request, lab_name=""):
lab_token = request.META.get('HTTP_AUTH_TOKEN')
lab_manager = LabManagerTracker.get(lab_name, lab_token)