Ejemplo n.º 1
0
def param_form(request, username, project, box, param_type=None, param_id=None):
    box = Box.retrieve(username, project, box, request.user, EDIT_RIGHT)
    param = None
    new = None
    success = False
    if param_id:
        try:
            param = BoxParam.objects.get(pk=param_id)
        except BoxParam.DoesNotExist:
            return HttpResponse("Your request returned no results.")
    else:
        if param_type not in ("text", "number"):
            return HttpResponse("Your request cannot be completed.")
        new = param_type
    if request.method == "POST":
        form = ParamForm(request.POST, new=new, param=param, box=box, action=request.path)
        if form.is_valid():
            args = {
                "name": form.cleaned_data.pop("parameter_name"),
                "box": form.cleaned_data.pop("box"),
                "subtype": form.cleaned_data.pop("subtype"),
                "css_class": form.cleaned_data["type"] == "number" and "input-mini" or "",
                "field_type": form.cleaned_data.pop("type"),
                "order": form.cleaned_data.pop("order"),
            }
            if "pk" in form.cleaned_data:
                args["pk"] = form.cleaned_data.pop("pk")
            args["constraints"] = dumps(form.cleaned_data)
            BoxParam(**args).save()
            success = True
    else:
        form = ParamForm(new=new, param=param, box=box, action=request.path)
    return render(request, "edit_param.html", {"form": form, "success": success})
Ejemplo n.º 2
0
def edit_box(request, username, project, box):
    status = "edit"
    box = Box.retrieve(username, project, box, request.user, EDIT_RIGHT)
    if request.method == "POST":
        form = BoxForm(request.POST, instance=box, action=box.edit_link(), project=box.project)
        if form.is_valid():
            try:
                form.save()
                status = "saved"
            except Exception:
                status = "error"
    else:
        form = BoxForm(instance=box, project=box.project, action=box.edit_link())
    return render(request, "edit_box.html", {"box": box, "edit_form": form, "status": status})
Ejemplo n.º 3
0
def box(request, username, project, box):
    run = None
    box = Box.retrieve(username, project, box, request.user)
    if request.method == "POST" and request.user.is_authenticated():
        launch_form = RunForm(request.POST, box=box, user=request.user)
        if launch_form.is_valid():
            try:
                new_run = Run(box=box, user=request.user.get_profile(), status=1, secret_key=str(uuid4()))
                new_run.lifetime = launch_form.cleaned_data.pop("lifetime")
                new_run.save()
                box_param = BoxParam.objects.filter(box=box)
                for param, value in launch_form.cleaned_data.items():
                    RunParam(value=(value or ""), run=new_run, box_param=box_param.get(name=param)).save()
                new_run.start()
                messages.success(request, "Run #%s launched successfully" % new_run.pk)
            except Exception:
                messages.error(request, COMMON_ERROR_MSG)
            return HttpResponseRedirect(box.link())
    else:
        launch_form = RunForm(box=box, user=request.user)
        if "cancel" in request.GET and request.user.is_authenticated():
            try:
                run_id = int(request.GET["cancel"])
                cancelled_run = Run.objects.get(pk=run_id)
                if cancelled_run.user == request.user.get_profile():
                    if cancelled_run.status in (1, 4):
                        cancelled_run.set_status("cancelled")
                    messages.success(request, "Run #%s cancelled successfully" % run_id)
            except:
                messages.error(request, "Sorry, we where unable to cancel this run...")
            return HttpResponseRedirect(box.link())
        elif "run" in request.GET:
            try:
                run_id = int(request.GET["run"])
                run = Run.objects.get(pk=run_id, box=box)
            except:
                messages.error(request, "Sorry, we where unable to find this run...")
    return render(request, "box.html", {"box": box, "launch_form": launch_form, "run": run})
Ejemplo n.º 4
0
def delete_param(request, username, project, box, param_id):
    box = Box.retrieve(username, project, box, request.user, EDIT_RIGHT)
    param = get_object_or_404(BoxParam, pk=param_id)
    param.delete()
    return HttpResponse("{status: 0}")