Exemple #1
0
def project_add(request):
    if request.method == "POST":
      form = ProjectForm(request.POST)
      if form.is_valid():
        form.instance.date_added = datetime.date.today()
        form.instance.date_updated = datetime.date.today()
        form.instance.owner = request.user
        try:
          form.save()
          messages.success(request, 'Successfully added the "' + form.instance.name + '" project!')
          return redirect("project_list")
        except:
          return HttpResponseServerError()
    else:
        form = ProjectForm()
    return render(request, 'projects/add.html', {"form" : form})
    return HttpResponse('Permission denied')
Exemple #2
0
def project_edit(request, project_id):
    project = get_object_or_404(Project, pk=project_id)
    if project.owned_by_user(request.user):
      if(request.method == "POST"):
        form = ProjectForm(request.POST, instance = project)
        if form.is_valid():
          try:
            form.save()
            messages.success(request, 'You have successfully edited the "' + project.name + '" project!')
            url = reverse('project_show', kwargs={'project_id': project.id})
            return HttpResponseRedirect(url)
          except:
            return HttpResponseServerError()
      else:
        form = ProjectForm(instance = project)
      return render(request, 'projects/edit.html', {"form" : form, "project" : project})
    else:
      messages.error(request, 'You have no permission to edit the "'+ project.name +'" project.')
      return render(request, 'projects/show.html', {"project" : project})