Пример #1
0
def create_income(request):
#================================================================================
# create income object
#================================================================================
    #dictionary that passes information to the template
    template = dict()

    # If the form has been submitted
    if request.method == 'POST': 
        form = IncomeForm(request.POST, request.FILES)

        #validate fields
        if form.is_valid(): # check if fields validated
            item = form.cleaned_data
            item = form.save(commit=False)
            item.budget = Budget.objects.get(term=item.term, year=item.year, position=item.position)
            item.type = "IN"
            item.creator = request.user
            form.save()
            return HttpResponseRedirect(reverse('transaction_confirm_transaction', kwargs={'id': item.id}))
            
    #else blank form   
    else:
        form = IncomeForm()

    template['form'] = form
    
    #tells the view which template to use, and to pass the template dictionary
    return render_to_response('transactions/create_income.htm',template, context_instance=RequestContext(request))
Пример #2
0
def create_income(request):
#================================================================================
# create income object
#================================================================================
    #dictionary that passes information to the template
    template = dict()
    
    # If the form has been submitted
    if request.method == 'POST': 
        form = IncomeForm(request.POST)

        #validate fields
        if form.is_valid(): # check if fields validated
            cleaned_data = form.cleaned_data
            form.save()
            return HttpResponseRedirect(reverse('index'))
            
    #else blank form   
    else:
        form = IncomeForm()

    template['form'] = form
    
    #tells the view which template to use, and to pass the template dictionary
    return render_to_response('transactions/create_income.htm',template, context_instance=RequestContext(request))
Пример #3
0
def edit_income(request, id):
#================================================================================
# edit specific transaction - general
#================================================================================
    template = dict()

    
    t = get_object_or_404(Income, pk=id)
    if request.method == 'POST': # If the form has been submitted...    
        form = IncomeForm(request.POST, instance=t)   
       
        #validate fields
        if form.is_valid(): # check if fields validated
            cleaned_data = form.cleaned_data
            form = form.save(commit=False) #save it to the db
            #.editor = request.user
            form.save()
    
            return HttpResponseRedirect(reverse('transaction_confirm_transaction', kwargs={'id': form.id})) # Redirect after POST
    else:
        form = IncomeForm(instance=t)
                
 
    template["t"] = t
    template["form"] = form #pass the form to template as "form" variable
       
    return render_to_response('transactions/edit_income.htm', template, context_instance=RequestContext(request))