Esempio n. 1
0
def milestone_detail(request, project_id, object_id=None):
    """
    Describes a milestone for a given project or a form to create a new
    milestone for that same project.
    """
    project = get_object_or_404(Project, pk=project_id)

    if object_id is None:
        milestone = None
        form_args = {}
    else:
        milestone = get_object_or_404(Milestone, pk=object_id)
        form_args = {"instance": milestone}

    if request.method == "POST":
        form = MilestoneForm(request.POST, **form_args)
        tasks_form = TasksForm(request.POST)
        if form.is_valid():
            milestone = form.save(commit=False)
            milestone.project = project
            milestone.save()
            return HttpResponseRedirect(milestone.get_absolute_url())
    else:
        form = MilestoneForm(**form_args)
        tasks_form = TasksForm()

    context = {"form": form,
               "tasks_form": tasks_form,
               "project": project,
               "object": milestone}
    return render_to_response("projects/milestone_form.html", context,
                              context_instance=RequestContext())
Esempio n. 2
0
def milestone_add_typed(request, project_id=None, response_format='html'):
    """Milestone add to preselected project"""

    project = None
    if project_id:
        project = get_object_or_404(Project, pk=project_id)
        if not request.user.profile.has_permission(project, mode='x'):
            project = None

    if request.POST:
        if 'cancel' not in request.POST:
            milestone = Milestone()
            form = MilestoneForm(
                request.user.profile, project_id, request.POST, instance=milestone)
            if form.is_valid():
                milestone = form.save()
                milestone.set_user_from_request(request)
                return HttpResponseRedirect(reverse('projects_milestone_view', args=[milestone.id]))
        else:
            return HttpResponseRedirect(reverse('projects'))
    else:
        form = MilestoneForm(request.user.profile, project_id)

    context = _get_default_context(request)
    context.update({'form': form, 'project': project})

    return render_to_response('projects/milestone_add_typed', context,
                              context_instance=RequestContext(request), response_format=response_format)
Esempio n. 3
0
def milestone_edit(request, milestone_id, response_format='html'):
    """Milestone edit page"""

    milestone = get_object_or_404(Milestone, pk=milestone_id)
    project = milestone.project
    if not request.user.profile.has_permission(milestone, mode='w'):
        return user_denied(request, message="You don't have access to this Milestone")

    if request.POST:
        if 'cancel' not in request.POST:
            form = MilestoneForm(
                request.user.profile, None, request.POST, instance=milestone)
            if form.is_valid():
                milestone = form.save()
                return HttpResponseRedirect(reverse('projects_milestone_view', args=[milestone.id]))
        else:
            return HttpResponseRedirect(reverse('projects_milestone_view', args=[milestone.id]))
    else:
        form = MilestoneForm(
            request.user.profile, None, instance=milestone)

    context = _get_default_context(request)
    context.update({'form': form,
                    'milestone': milestone,
                    'project': project})

    return render_to_response('projects/milestone_edit', context,
                              context_instance=RequestContext(request), response_format=response_format)
Esempio n. 4
0
def milestone_create(request, slug):
    if request.method == 'POST':
        json_data = {}
        milestone_dict = request.POST.copy()
        project_id = Project.objects.get(slug = slug).id
        milestone_dict['project'] = project_id
        milestone_form = MilestoneForm(request.user, milestone_dict)
        if milestone_form.is_valid():
            milestone_form.save()
            json_data['error'] = False
            return HttpResponse(json.dumps(json_data), content_type = 'application/json')
        else:
            json_data['error'] = True
            json_data['form_errors'] = milestone_form.errors
            return HttpResponse(json.dumps(json_data), content_type = 'application/json')
    else:
        return render(request, 'project/milestone.html')
Esempio n. 5
0
def milestone_add(request, response_format='html'):
    """New milestone form"""

    if request.POST:
        if 'cancel' not in request.POST:
            milestone = Milestone()
            form = MilestoneForm(
                request.user.profile, None, request.POST, instance=milestone)
            if form.is_valid():
                milestone = form.save()
                milestone.set_user_from_request(request)
                return HttpResponseRedirect(reverse('projects_milestone_view', args=[milestone.id]))
        else:
            return HttpResponseRedirect(reverse('projects'))
    else:
        form = MilestoneForm(request.user.profile, None)

    context = _get_default_context(request)
    context.update({'form': form})

    return render_to_response('projects/milestone_add', context,
                              context_instance=RequestContext(request), response_format=response_format)