コード例 #1
0
ファイル: views.py プロジェクト: alexnjoyce/461designproject
def view_budgets(request, year=None, term=None, account=None):
#===========================================================================
# view all budgets
#===========================================================================

    template = dict()
    
    budgets = Budget.objects.all()
    
    if not account:
        if not is_admin(request.user):
            budgets = budgets.filter(approved=True)
    else:
        if is_admin(request.user):
            budgets = budgets.filter(approved=False)
        else:
            budgets = budgets.filter(creator=request.user)
    
    terms = []
    terms.append('S')
    terms.append('W')
    terms.append('F')
    template['terms'] = terms
    
    years_list = budgets.values('year').distinct().order_by()
    years =[]
    count = 0
    for y in years_list:
        years.append(y['year'])
        
    
    template['years'] = years
    template['all'] = "all"
    
    
    if year:
        budgets = budgets.filter(year=year)
        template['year'] = int(year)
    if term:
        budgets = budgets.filter(term=term)
        template['term'] = term    
   
    template['account'] = account
    template['budgets'] = budgets
    
    return render_to_response('budget/view_budget.htm',template, context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: alexnjoyce/461designproject
def view_transactions(request, year=None, term=None, account=None):
#================================================================================
# view all transactions
#================================================================================
    template = dict()
    
    expenditures = Expenditure.objects.all()
    incomes = Income.objects.all()
    transactions = Transaction.objects.all()
    
    if not account:
        if not is_admin(request.user):
            expenditures = expenditures.filter(approved=True)
            incomes = incomes.filter(approved=True)
            transactions = transactions.filter(approved=True)
    else:
        if is_admin(request.user):
            expenditures = expenditures.filter(approved=False)
            incomes = incomes.filter(approved=False)
            transactions = transactions.filter(approved=False)  
        else:
            expenditures = expenditures.filter(creator=request.user)
            incomes = incomes.filter(creator=request.user)
            transactions = transactions.filter(creator=request.user)           
        
    
    terms = []
    terms.append('S')
    terms.append('W')
    terms.append('F')
    template['terms'] = terms
    
    years_list = transactions.values('year').distinct().order_by()
    years =[]
    count = 0
    for y in years_list:
        years.append(y['year'])
        
    
    template['years'] = years
    template['all'] = "all"
    
    
    if year:
        incomes = incomes.filter(year=year)
        expenditures = expenditures.filter(year=year)
        template['year'] = int(year)
    if term:
        incomes = incomes.filter(term=term)
        expenditures = expenditures.filter(term=term)
        template['term'] = term    
   
    
    template['incomes'] = incomes
    template['expenditures'] = expenditures
    template['transactions'] = transactions
    
    expenditures_total = expenditures.aggregate(total=Sum('amount'))
    incomes_total = incomes.aggregate(total=Sum('amount'))
    
    #save variables to be passed into the template for use there
    template['expenditures'] = expenditures
    template['expenditures_total'] = expenditures_total
    template['incomes_total'] = incomes_total
    template['incomes'] = incomes
    
    template['account'] = account

    
    
    return render_to_response('transactions/view_transactions.htm', template, context_instance=RequestContext(request))