Beispiel #1
0
def request(req):
    try:
        d = Demo(email=req.POST['email'])
    except:
        return render(req, 'provision/request.html', {'require_approval': settings.REQUIRE_APPROVAL})
    if settings.REQUIRE_APPROVAL:
        logger.info("%s: new demo request", d)
        d.do_request_approval()
    else:
        d.do_approve(False)
        if req.REQUEST.has_key('format') and req.REQUEST['format'] == 'json':
            launch.delay(d)
            return HttpResponse(json.dumps(d.demo_info()), mimetype="application/json")
        else:
            d.do_launch()
    return HttpResponseRedirect(d.get_absolute_url())
Beispiel #2
0
def demo(req, demo_id):
    demo_id=Signer().unsign(demo_id)
    d = get_object_or_404(Demo, pk=demo_id)
    if d.launchable() and req.method == 'POST' :
        if req.REQUEST.has_key('format') and req.REQUEST['format'] == 'json':
            launch.delay(d)
        else:
            d.do_launch()

    if req.REQUEST.has_key('format') and req.REQUEST['format'] == 'json':
        return HttpResponse(json.dumps(d.demo_info()), mimetype="application/json")

    if d.status in (Demo.SHUTTING_DOWN, Demo.OVER):
        return render(req,'provision/shutdown.html', {'demo': d})
    elif d.status == Demo.RUNNING:
        return render(req,'provision/running.html', {'demo': d, 'nodes': d.node_set.all().order_by('type')})
    elif d.status == Demo.AWAITING_LAUNCH:
        return render(req,'provision/launch.html', {'demo': d})
    elif d.status == Demo.AWAITING_APPROVAL:
        return render(req,'provision/awaiting_approval.html', {'demo': d})
    else:
        return HttpResponseServerError("Demo status: %s" %d.get_status_display())