Beispiel #1
0
def project_view(request, project_id):
    """
    - return project corresponding to project_id
    - handle project modification form submition
    - raise 404 if project is not found or project doesn't belong to
    the current user
    """
    if request.user.is_superuser:
        project = get_object_or_404(Project, pk=project_id)
    else:
        project = get_object_or_404(Project, owner=request.user, pk=project_id)
    if request.method == "POST":
        form = ProjectForm(request.POST, instance=project)
        if form.is_valid():
            form.save()
    else:
        form = ProjectForm(instance=project)

    context = {
        'project':
        project,
        'new_application_form':
        NewApplicationForm({'project_id': project.id},
                           prefix='new_application'),
        'project_form':
        form
    }
    return render_response(request, 'project/project_view.html', context)
Beispiel #2
0
 def post(self, request, id):
     project_form = ProjectForm(request.POST)
     if project_form.is_valid():
         project = Project.objects.get(id=id)
         project.name = request.POST['name']
         project.type = request.POST['type']
         project.detail = request.POST['detail']
         project.creator = UserProfile.objects.get(username=request.user)
         project.save()
     return HttpResponseRedirect(reverse('project_list'))
Beispiel #3
0
    def post(self, request):
        project_form = ProjectForm(request.POST)

        if project_form.is_valid():
            name = request.POST['name']
            type = request.POST['type']
            detail = request.POST['detail']
            creator = UserProfile.objects.get(username=request.user)
            project = Project(name=name,
                              type=type,
                              detail=detail,
                              creator=creator)
            project.save()
        else:
            return render(request, 'project_add.html',
                          {'error': project_form.errors})
        return HttpResponseRedirect(reverse('project_list'))
Beispiel #4
0
def project_view(request, project_id):
    """
    - return project corresponding to project_id
    - handle project modification form submition
    - raise 404 if project is not found or project doesn't belong to
    the current user
    """
    if request.user.is_superuser:
        project = get_object_or_404(Project, pk=project_id)
    else:
        project = get_object_or_404(Project, owner=request.user, pk=project_id)
    if request.method == "POST":
        form = ProjectForm(request.POST, instance=project)
        if form.is_valid():
            form.save()
    else:
        form = ProjectForm(instance=project)

    context = {'project': project,
               'new_application_form': NewApplicationForm(
                   {'project_id': project.id}, prefix='new_application'),
               'project_form': form}
    return render_response(request, 'project/project_view.html', context)