Esempio n. 1
0
def create_project(request):
    if request.POST:
        form = ProjectForm(request.POST)
        if form.is_valid():
            elem = form.save()
            return HttpResponseRedirect(object_link(elem))
        else:
            return HttpResponseBadRequest()

    return HttpResponseNotAllowed(['POST'])
Esempio n. 2
0
def create_project(request):
    if request.POST:
        form = ProjectForm(request.POST)
        if form.is_valid():
            elem = form.save()
            return HttpResponseRedirect(object_link(elem))
        else:
            return HttpResponseBadRequest()

    return HttpResponseNotAllowed(['POST'])
Esempio n. 3
0
def project_add(request):
    if request.user.is_authenticated():
        if request.method == "POST":
            form = ProjectForm(request.POST)
            if form.is_valid():
                form.instance.user = request.user
                form.save()
                request.flash["notice"] = "Project added"
                return redirect(index)
        else:
            form = ProjectForm()
    else:
        return redirect(login_user)

    return render(request, "projects/add.html", {"form": form})
Esempio n. 4
0
def edit(request, project_id):
    if request.user.is_authenticated():
        project = get_object_or_404(Project, pk=project_id)
        if project.owner_by_user(request.user):
            if request.method == "POST":
                form = ProjectForm(request.POST, instance=project)
                if form.is_valid():
                    form.save()
                    request.flash["notice"] = "Project edited"
                    return redirect("detail", project.id)
            else:
                form = ProjectForm(instance=project)
            return render(request, "projects/edit.html", {"form": form, "project": project})
        else:
            request.flash["warning"] = "You are not the owner of this project"
            return redirect("detail", project.id)
    else:
        return redirect(login_user)
Esempio n. 5
0
def projects(request):
    return render_to_response(
        "projects.html",
        RequestContext(
            request, {
                "title": "Projects",
                "form": ProjectForm(),
                "projects": Project.objects.all(),
                "formAction": "/create_project/"
            }))