コード例 #1
0
ファイル: views.py プロジェクト: jexhson/rbx-saas
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})
コード例 #2
0
ファイル: views.py プロジェクト: jexhson/rbx-saas
def project(request, username, project):
    project = Project.retrieve(username, project, request.user)
    if request.method == "POST":
        box_form = BoxForm(
            request.POST, project=project, form_class="well", initial={"project": project}, action=project.link("boxes")
        )
        if box_form.is_valid():
            try:
                new_box = box_form.save()
                messages.success(request, "%s box successfully saved" % new_box.name)
                return HttpResponseRedirect(new_box.link())
            except:
                messages.error(request, COMMON_ERROR_MSG)
                return HttpResponseRedirect(project.link())
    else:
        box_form = BoxForm(
            project=project, form_class="well", initial={"project": project}, action=project.link("boxes")
        )
    return render(
        request, "project.html", {"project": project, "box_error": request.method == "POST", "box_form": box_form}
    )