Beispiel #1
0
def project_detail_update(request,client_id, project):
    #get the latest project_update OBJECT to show#
    project_update = ProjectUpdate.objects.filter(project = project.id).latest('id')
    project_history = ProjectUpdate.objects.filter(project = project.id).filter(id__lt = project_update.id)

    #POPULATE revenue list#
    if project_update.expected_start is None or project_update.expected_end is None:
        revenue_list = []
    else:
        revenue_list = get_revenue_list(project,project_update)

    #POPULATE invoice list#
    if project_update.expected_start is None or project_update.expected_end is None:
        invoice_list = []
    else:
        invoice_list = get_invoice_list(project,project_update)


    #SHOW the GATE button or not
    have_gate = True
    '''
    if ProjectGate.objects.exists() and ProjectGate.objects.filter(project = project).exists():
            project_gate = ProjectGate.objects.filter(project = project).latest('id')
            if  not project_gate.project_pass:
                have_gate = True
    else:
        have_gate = True
    '''

    #SAVE METHOD#
    if request.method == 'POST':
        my_data = request.POST
        project_update_form = ProjectUpdateForm(instance=ProjectUpdate(), data=my_data)#save a new project_update everytime
        if  project_update_form.is_valid():
            project_update = project_update_form.save(commit=False)
            project_update.project = project
            project_update.save()#save project_update
            return HttpResponseRedirect(reverse('project:project-detail', args=(client_id,project.id,)))
    #if NOT save, populate it
    else:
        project_update_form = ProjectUpdateForm(instance=project_update)


    return render(request, 'project/project_detail.html', {'project':project,
        'project_update':project_update_form, 'project_history':project_history,
        'revenueFormList': revenue_list,'invoiceFormList':invoice_list,
        'client_id':client_id, 'have_gate':have_gate
        })
Beispiel #2
0
def project_detail_new(request,client_id, project):
    project_update = ProjectUpdate()
    #SAVE METHOD#
    if request.method == 'POST':
        my_data = request.POST
        project_update_form = ProjectUpdateForm(instance=ProjectUpdate(), data=my_data)

        if  project_update_form.is_valid():
            project_update = project_update_form.save(commit=False)
            project_update.project = project
            project_update.save()#save project_update
            response = project_detail_update(request,client_id, project)
            return response #return the project_detail_update page

    #if NOT save, populate it
    else:
        project_update_form = ProjectUpdateForm(instance=project_update)

    return render(request, 'project/project_detail_new.html', {'project':project,
        'project_update':project_update_form, 'client_id':client_id})