From: sms1097 Date: Thu, 19 Mar 2020 21:08:12 +0000 (-0400) Subject: Able to delete configurations and view lab details X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F18%2F69818%2F3;p=laas.git Able to delete configurations and view lab details Change-Id: Ib15c86d84f4cc7e7745551889ce91c89b5de46e2 Signed-off-by: Sean Smith Change-Id: Id6748c6bea67773a861921394d88579730246598 --- diff --git a/src/account/views.py b/src/account/views.py index a8bb02b..0135993 100644 --- a/src/account/views.py +++ b/src/account/views.py @@ -29,6 +29,7 @@ from django.shortcuts import render from jira import JIRA from rest_framework.authtoken.models import Token + from account.forms import AccountSettingsForm from account.jira_util import SignatureMethod_RSA_SHA1 from account.models import UserProfile @@ -177,20 +178,15 @@ def account_resource_view(request): if not request.user.is_authenticated: return render(request, "dashboard/login.html", {'title': 'Authentication Required'}) template = "account/resource_list.html" - resources = ResourceTemplate.objects.filter( - owner=request.user).prefetch_related("configbundle_set") - mapping = {} - resource_list = [] - booking_mapping = {} - for grb in resources: - resource_list.append(grb) - mapping[grb.id] = [{"id": x.id, "name": x.name} for x in grb.configbundle_set.all()] - if Booking.objects.filter(resource__template=grb, end__gt=timezone.now()).exists(): - booking_mapping[grb.id] = "true" + + active_bundles = [book.bundle for book in Booking.objects.filter( + owner=request.user, end__gte=timezone.now())] + active_resources = [bundle.template.id for bundle in active_bundles] + resource_list = list(ResourceTemplate.objects.filter(owner=request.user)) + context = { "resources": resource_list, - "grb_mapping": mapping, - "booking_mapping": booking_mapping, + "active_resources": active_resources, "title": "My Resources" } return render(request, template, context=context) @@ -260,7 +256,7 @@ def configuration_delete_view(request, config_id=None): config = get_object_or_404(ResourceTemplate, pk=config_id) if not request.user.id == config.owner.id: return HttpResponse('no') # 403? - if Booking.objects.filter(config_bundle=config, end__gt=timezone.now()).exists(): + if Booking.objects.filter(resource__template=config, end__gt=timezone.now()).exists(): return HttpResponse('no') config.delete() return HttpResponse('') diff --git a/src/dashboard/views.py b/src/dashboard/views.py index 498bd9d..77561c0 100644 --- a/src/dashboard/views.py +++ b/src/dashboard/views.py @@ -43,7 +43,7 @@ def lab_detail_view(request, lab_name): { 'title': "Lab Overview", 'lab': lab, - 'hostprofiles': lab.hostprofiles.all(), + 'hostprofiles': ResourceProfile.objects.filter(labs=lab), 'images': images, } ) diff --git a/src/templates/base/account/configuration_list.html b/src/templates/base/account/configuration_list.html index 206c203..fee6e83 100644 --- a/src/templates/base/account/configuration_list.html +++ b/src/templates/base/account/configuration_list.html @@ -41,6 +41,11 @@ var formData = ajaxForm.serialize(); req = new XMLHttpRequest(); var url = "delete/" + current_config_id; + req.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + location.reload(); + } + }; req.open("POST", url, true); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req.onerror = function() { alert("problem submitting form"); } diff --git a/src/templates/base/account/resource_list.html b/src/templates/base/account/resource_list.html index 65b46f1..33ccaff 100644 --- a/src/templates/base/account/resource_list.html +++ b/src/templates/base/account/resource_list.html @@ -29,23 +29,20 @@ {% endfor %}