Пример #1
0
def create_expenditure(request):
#================================================================================
# create expenditure object
#================================================================================
    template = dict()
    
    # If the form has been submitted
    if request.method == 'POST': 
        form = ExpenditureForm(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 = "EX"
            item.creator = request.user
            form.save()
            return HttpResponseRedirect(reverse('transaction_confirm_transaction', kwargs={'id': item.id}))
        
    
    #else blank form   
    else:
        form = ExpenditureForm()

    template['form'] = form
    
    
    return render_to_response('transactions/create_expenditure.htm',template, context_instance=RequestContext(request))
Пример #2
0
def edit_expenditure(request, id):
#================================================================================
# edit specific transaction - general
#================================================================================
    template = dict()

    t = get_object_or_404(Expenditure, pk=id)
    if request.method == 'POST': # If the form has been submitted...
        form = ExpenditureForm(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 
            #form.editor = request.user
            form.save()
    
            return HttpResponseRedirect(reverse('transaction_confirm_transaction', kwargs={'id': form.id})) # Redirect after POST
                     
    else:
        form = ExpenditureForm(instance=t)
    
    template["t"] = t
    template["form"] = form #pass the form to template as "form" variable    

    return render_to_response('transactions/edit_expenditure.htm', template, context_instance=RequestContext(request))    
Пример #3
0
def create_expenditure(request):
#================================================================================
# create expenditure object
#================================================================================
    template = dict()
    
    # If the form has been submitted
    if request.method == 'POST': 
        form = ExpenditureForm(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 = ExpenditureForm()

    template['form'] = form
    
    return render_to_response('transactions/create_expenditure.htm',template, context_instance=RequestContext(request))