aboutsummaryrefslogtreecommitdiffstats
path: root/src/booking/views.py
diff options
context:
space:
mode:
authorSawyer Bergeron <sawyerbergeron@gmail.com>2019-01-17 11:30:35 -0500
committerSawyer Bergeron <sawyerbergeron@gmail.com>2019-01-18 11:27:53 -0500
commitd8e2dbb57cc90ebdffb9ca463b91948b9b634918 (patch)
tree48580e2be6ff64904f83e8539ad390afbcaa6bb1 /src/booking/views.py
parent4f02f83fe61740a439694b8d37bf4962ffaa0e01 (diff)
Add Quick-Booking Workflow
Users can now quickly provision a single-host pod without having to configure unecessary networking. This is intended to be analogous to the workflow used during LaaS 1.0, and to speed up the process of creating a booking for users who do not need more than a single host (for virtual deployments) Change-Id: Ia19cea9a42bbb1df57aad05af8f8ea821395664d Signed-off-by: Sawyer Bergeron <sawyerbergeron@gmail.com>
Diffstat (limited to 'src/booking/views.py')
-rw-r--r--src/booking/views.py64
1 files changed, 48 insertions, 16 deletions
diff --git a/src/booking/views.py b/src/booking/views.py
index 29b53e2..bc1d2c9 100644
--- a/src/booking/views.py
+++ b/src/booking/views.py
@@ -15,28 +15,60 @@ from django.utils import timezone
from django.views import View
from django.views.generic import TemplateView
from django.shortcuts import redirect, render
-import json
-from resource_inventory.models import ResourceBundle
+from account.models import Lab
from resource_inventory.resource_manager import ResourceManager
-from booking.models import Booking, Installer, Opsys
+from resource_inventory.models import ResourceBundle
+from booking.models import Booking
from booking.stats import StatisticsManager
+from workflow.views import login
+from booking.forms import QuickBookingForm
+from booking.quick_deployer import create_from_form, drop_filter
+
+
+def quick_create_clear_fields(request):
+ request.session['quick_create_forminfo'] = None
+
+
+def quick_create(request):
+ if not request.user.is_authenticated:
+ return login(request)
+
+ if request.method == 'GET':
+ context = {}
+
+ r_manager = ResourceManager.getInstance()
+ profiles = {}
+ for lab in Lab.objects.all():
+ profiles[str(lab)] = r_manager.getAvailableHostTypes(lab)
+
+ context['lab_profile_map'] = profiles
+
+ context['form'] = QuickBookingForm(initial={}, chosen_users=[], default_user=request.user.username, user=request.user)
+ context.update(drop_filter(request.user))
-def drop_filter(context):
- installer_filter = {}
- for os in Opsys.objects.all():
- installer_filter[os.id] = []
- for installer in os.sup_installers.all():
- installer_filter[os.id].append(installer.id)
+ return render(request, 'booking/quick_deploy.html', context)
+ if request.method == 'POST':
+ form = QuickBookingForm(request.POST, user=request.user)
+ context = {}
+ context['lab_profile_map'] = {}
+ context['form'] = form
- scenario_filter = {}
- for installer in Installer.objects.all():
- scenario_filter[installer.id] = []
- for scenario in installer.sup_scenarios.all():
- scenario_filter[installer.id].append(scenario.id)
+ if form.is_valid():
+ try:
+ create_from_form(form, request)
+ except Exception as e:
+ messages.error(request, "Whoops, looks like an error occurred. "
+ "Let the admins know that you got the following message: " + str(e))
+ return render(request, 'workflow/exit_redirect.html', context)
- context.update({'installer_filter': json.dumps(installer_filter), 'scenario_filter': json.dumps(scenario_filter)})
+ messages.success(request, "We've processed your request. "
+ "Check Account->My Bookings for the status of your new booking")
+ return render(request, 'workflow/exit_redirect.html', context)
+ else:
+ messages.error(request, "Looks like the form didn't validate. Check that you entered everything correctly")
+ return render(request, 'booking/quick_deploy.html', context)
class BookingView(TemplateView):
@@ -128,6 +160,6 @@ def booking_stats_view(request):
def booking_stats_json(request):
try:
span = int(request.GET.get("days", 14))
- except:
+ except Exception:
span = 14
return JsonResponse(StatisticsManager.getContinuousBookingTimeSeries(span), safe=False)