Пример #1
0
def project_subprojects(request, project_slug):
    """Project subprojects view and form view"""
    project = get_object_or_404(Project.objects.for_admin_user(request.user),
                                slug=project_slug)

    form_kwargs = {
        'parent': project,
        'user': request.user,
    }
    if request.method == 'POST':
        form = SubprojectForm(request.POST, **form_kwargs)
        if form.is_valid():
            form.save()
            project_dashboard = reverse('projects_subprojects',
                                        args=[project.slug])
            return HttpResponseRedirect(project_dashboard)
    else:
        form = SubprojectForm(**form_kwargs)

    subprojects = project.subprojects.all()

    return render_to_response('projects/project_subprojects.html', {
        'form': form,
        'project': project,
        'subprojects': subprojects
    },
                              context_instance=RequestContext(request))
Пример #2
0
def project_subprojects(request, project_slug):
    """Project subprojects view and form view"""
    project = get_object_or_404(Project.objects.for_admin_user(request.user),
                                slug=project_slug)

    form_kwargs = {
        'parent': project,
        'user': request.user,
    }
    if request.method == 'POST':
        form = SubprojectForm(request.POST, **form_kwargs)
        if form.is_valid():
            form.save()
            project_dashboard = reverse(
                'projects_subprojects', args=[project.slug])
            return HttpResponseRedirect(project_dashboard)
    else:
        form = SubprojectForm(**form_kwargs)

    subprojects = project.subprojects.all()

    return render_to_response(
        'projects/project_subprojects.html',
        {'form': form, 'project': project, 'subprojects': subprojects},
        context_instance=RequestContext(request)
    )
Пример #3
0
def project_subprojects(request, project_slug):
    project = get_object_or_404(request.user.projects.live(), slug=project_slug)

    form = SubprojectForm(data=request.POST or None, parent=project)

    if request.method == 'POST' and form.is_valid():
        form.save()
        project_dashboard = reverse('projects_detail', args=[project.slug])
        return HttpResponseRedirect(project_dashboard)

    subprojects = project.subprojects.all()

    return render_to_response(
        'projects/project_subprojects.html',
        {'form': form, 'project': project, 'subprojects': subprojects},
        context_instance=RequestContext(request)
    )
Пример #4
0
    def test_admin_of_subproject_can_add_it(self):
        user = get(User)
        project = get(Project, slug='mainproject')
        project.users.add(user)
        subproject = get(Project, slug='subproject')
        subproject.users.add(user)

        # Works now as user is admin of subproject.
        form = SubprojectForm({'subproject': subproject.slug},
                              parent=project,
                              user=user)
        # Fails because user does not own subproject.
        form.full_clean()
        self.assertTrue(form.is_valid())
        form.save()

        self.assertEqual([r.child for r in project.subprojects.all()],
                         [subproject])
Пример #5
0
    def test_admin_of_subproject_can_add_it(self):
        user = get(User)
        project = get(Project, slug='mainproject')
        project.users.add(user)
        subproject = get(Project, slug='subproject')
        subproject.users.add(user)

        # Works now as user is admin of subproject.
        form = SubprojectForm({'subproject': subproject.slug},
                              parent=project, user=user)
        # Fails because user does not own subproject.
        form.full_clean()
        self.assertTrue(form.is_valid())
        form.save()

        self.assertEqual(
            [r.child for r in project.subprojects.all()],
            [subproject])
Пример #6
0
def project_subprojects(request, project_slug):
    project = get_object_or_404(request.user.projects.live(),
                                slug=project_slug)

    form = SubprojectForm(data=request.POST or None, parent=project)

    if request.method == 'POST' and form.is_valid():
        form.save()
        project_dashboard = reverse('projects_detail', args=[project.slug])
        return HttpResponseRedirect(project_dashboard)

    subprojects = project.subprojects.all()

    return render_to_response('projects/project_subprojects.html', {
        'form': form,
        'project': project,
        'subprojects': subprojects
    },
                              context_instance=RequestContext(request))
Пример #7
0
def project_subprojects(request, project_slug):
    project = get_object_or_404(Project.objects.for_admin_user(request.user), slug=project_slug)

    form_kwargs = {"parent": project, "user": request.user}
    if request.method == "POST":
        form = SubprojectForm(request.POST, **form_kwargs)
        if form.is_valid():
            form.save()
            project_dashboard = reverse("projects_subprojects", args=[project.slug])
            return HttpResponseRedirect(project_dashboard)
    else:
        form = SubprojectForm(**form_kwargs)

    subprojects = project.subprojects.all()

    return render_to_response(
        "projects/project_subprojects.html",
        {"form": form, "project": project, "subprojects": subprojects},
        context_instance=RequestContext(request),
    )