Ejemplo n.º 1
0
def instrument_roles_edit(request, id):
    ctx = inject_permissions_into_context(RequestContext(request), request)
    if not ctx["change_aigoals"]:
        return render(request, "permissions.html", context_instance=RequestContext(request))

    ob = get_object_or_404(AiTreatyGoalRole, pk=id)
    if request.method == "POST":
        form = AiTreatyGoalRoleForm(request.POST, user=request.user, instance=ob)
        ctx["form"] = form
        if "delete" in request.POST.keys():
            if ctx["delete_aitreatygoalrole"]:
                if "confirmed" in request.POST.keys():
                    ob.delete()
                    messages.success(request, "Record has been successfully removed")
                    return redirect(reverse("aichi.views.instrument_roles"), request={})

                elif request.POST.has_key("cancel"):
                    return render(request, "instrument_role/edit.html", context_instance=ctx)

                else:
                    return render(request, "instrument_role/delete.html", context_instance=ctx)
            else:
                messages.error(request, "You do not have sufficient privileges to delete this record")

        elif request.POST.has_key("save"):
            if form.is_valid():
                form.save()
                messages.success(request, "Record has been successfully updated")
                return redirect(reverse("aichi.views.instrument_roles"), request={})

    else:
        form = AiTreatyGoalRoleForm(user=request.user, instance=ob)
        ctx["form"] = form

    return render(request, "instrument_role/edit.html", context_instance=ctx)
Ejemplo n.º 2
0
def instrument_roles_new(request):
    ctx = inject_permissions_into_context(RequestContext(request), request)
    if not ctx["add_aitreatygoalrole"]:
        return render(request, "permissions.html", context_instance=RequestContext(request))

    if request.method == "POST":
        form = AiTreatyGoalRoleForm(request.POST, user=request.user)
        if form.is_valid():
            form.save()
            messages.success(request, "Record has been successfully created")
            return redirect(reverse("aichi.views.instrument_roles"), request={})
    else:
        form = AiTreatyGoalRoleForm(user=request.user)
    ctx["form"] = form

    return render(request, "instrument_role/edit.html", context_instance=ctx)