aboutsummaryrefslogtreecommitdiffstats
path: root/src/workflow/views.py
blob: 08ed22b9e7259c4cc29ad22d81420e79d6788f26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
##############################################################################
# Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

import json
from django.shortcuts import render
from laas_dashboard.settings import TEMPLATE_OVERRIDE
from django.http import HttpResponse
from django.http.response import JsonResponse
from workflow.forms import BookingMetaForm
from api.views import liblaas_request, make_booking


def no_workflow(request):
    return render(request, 'workflow/no_workflow.html', {'title': "Not Found"}, status=404)


def login(request):
    return render(request, "dashboard/login.html", {'title': 'Authentication Required'})

def design_a_pod_view(request):
    if request.method == "GET":
        if not request.user.is_authenticated:
            return login(request)
        template = "workflow/design_a_pod.html"
        context = {
            "dashboard": str(TEMPLATE_OVERRIDE)
        }
        return render(request, template, context)
    
    if request.method == "POST":
        print("forwarding request to liblaas...")
        return liblaas_request(request)

    return HttpResponse(status=405)

def book_a_pod_view(request):
    if request.method == "GET":
        if not request.user.is_authenticated:
            return login(request)
        template = "workflow/book_a_pod.html"
        context = {
            "dashboard": str(TEMPLATE_OVERRIDE),
            "form": BookingMetaForm(initial={}, user_initial=[], owner=request.user),
        }
        return render(request, template, context)
    
    if request.method == "POST":
        print("forwarding request to liblaas...")
        return liblaas_request(request)

    # Using PUT to signal that we do not want to talk to liblaas
    if request.method == "PUT":
        return make_booking(request)

    return HttpResponse(status=405)