diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/api/urls.py | 5 | ||||
-rw-r--r-- | src/api/views.py | 37 | ||||
-rw-r--r-- | src/resource_inventory/resource_manager.py | 7 |
3 files changed, 30 insertions, 19 deletions
diff --git a/src/api/urls.py b/src/api/urls.py index 1878d9c..52a6fc7 100644 --- a/src/api/urls.py +++ b/src/api/urls.py @@ -52,7 +52,8 @@ from api.views import ( images_for_template, specific_booking, extend_booking, - all_users + all_users, + list_labs ) urlpatterns = [ @@ -82,7 +83,7 @@ urlpatterns = [ path('resource_inventory/<int:template_id>/images', images_for_template), path('users', all_users), - path('labs', all_labs), + path('labs', list_labs), url(r'^token$', GenerateTokenView.as_view(), name='generate_token'), ] diff --git a/src/api/views.py b/src/api/views.py index 84085b4..1793c79 100644 --- a/src/api/views.py +++ b/src/api/views.py @@ -11,6 +11,7 @@ import json import math import traceback +import sys from datetime import timedelta from django.contrib.auth.decorators import login_required @@ -34,6 +35,7 @@ from notifier.manager import NotificationHandler from analytics.models import ActiveVPNUser from booking.quick_deployer import create_from_API from resource_inventory.models import ResourceTemplate +from django.db.models import Q """ @@ -362,9 +364,13 @@ def make_booking(request): try: booking = create_from_API(request.body, token.user) - except Exception as e: + + except Exception: + finalTrace = '' exc_type, exc_value, exc_traceback = sys.exc_info() - return HttpResponse(str(traceback.format_exception(exc_type, exc_value, exc_traceback)), status=400) + for i in traceback.format_exception(exc_type, exc_value, exc_traceback): + finalTrace += '<br>' + i.strip() + return HttpResponse(finalTrace, status=400) sbooking = AutomationAPIManager.serialize_booking(booking) return JsonResponse(sbooking, safe=False) @@ -419,7 +425,7 @@ def images_for_template(request, template_id=""): """ User API Views """ -lab_info + def all_users(request): token = auth_and_log(request, 'users') @@ -428,7 +434,7 @@ def all_users(request): return HttpResponse('Unauthorized', status=401) users = [AutomationAPIManager.serialize_userprofile(up) - for up in UserProfile.objects.exclude(user=token.user)] + for up in UserProfile.objects.filter(public_user=True)] return JsonResponse(users, safe=False) @@ -438,21 +444,20 @@ Lab API Views """ -def all_labs(): - lab_list=[] +def list_labs(request): + lab_list = [] for lab in Lab.objects.all(): lab_info = { - 'name':lab.name, - 'username':lab.lab_user.username, - 'status':lab.status, - 'project':lab.project, - 'description':lab.description, - 'location':lab.location, - 'info':lab.lab_info_link, - 'email':lab.contact_email, - 'phone':lab.contact_phone + 'name': lab.name, + 'username': lab.lab_user.username, + 'status': lab.status, + 'project': lab.project, + 'description': lab.description, + 'location': lab.location, + 'info': lab.lab_info_link, + 'email': lab.contact_email, + 'phone': lab.contact_phone } lab_list.append(lab_info) return JsonResponse(lab_list, safe=False) - diff --git a/src/resource_inventory/resource_manager.py b/src/resource_inventory/resource_manager.py index 1935e0c..37bf33c 100644 --- a/src/resource_inventory/resource_manager.py +++ b/src/resource_inventory/resource_manager.py @@ -6,14 +6,16 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import annotations + import re -import typing from typing import Optional from django.db.models import Q from dashboard.exceptions import ResourceAvailabilityException from resource_inventory.models import ( + Resource, ResourceBundle, ResourceTemplate, ResourceConfiguration, @@ -23,6 +25,9 @@ from resource_inventory.models import ( InterfaceConfiguration, ) +from account.models import Lab +from django.contrib.auth.models import User + class ResourceManager: |