def account_list(request, label_filter = None): """ Render the listing of all accounts. On GET, it will return a listing of all accounts. """ # Recover the groups the accessor is in request_user = request.user account_list = Account.objects.all() return_list = [] # Get list of labels (there is probably some SQL command/a better way to do this) label_list = [] #for account in account_list: # for label in account.labels: # label_list.append(label) # Remove duplicate labels label_list = list(set(label_list)) # TODO: Figure out how to grab this without linear search for account in account_list: if authenticate_account(request_user, account) and (not label_filter or account.labels.filter(name=label_filter)): return_list.append(account) context = RequestContext(request, {"section":"accounts", "account_list":return_list, "label_list":label_list}) return render_to_response("accounts/list.html", context)
def account_update(request, account_id, *args, **kargs): """ Update an individual account. On GET, it will return a form to update the account. On POST, it will update information about the account. """ account = get_object_or_404(Account, pk=account_id) # Check that the user can access it, or 403 if not authenticate_account(request.user, account): raise PermissionDenied() if request.method == 'POST': # Try to validate and update account_form = AccountForm(request.POST, instance=account) if account_form.is_valid(): account = account_form.save() return HttpResponseRedirect('/account') else: # Populate the form with the current account's data account_form = AccountForm(instance=account) # Pass back the form we have, after updating CSRF kargs.update(csrf(request)) context = RequestContext(request, dict(section="accounts", form=account_form, mode="update", account=account, **kargs)) return render_to_response("accounts/form.html", context)
def account_update(request, account_id, *args, **kargs): """ Update an individual account. On GET, it will return a form to update the account. On POST, it will update information about the account. """ account = get_object_or_404(Account, pk=account_id) # Check that the user can access it, or 403 if not authenticate_account(request.user, account): raise PermissionDenied() if request.method == 'POST': # Try to validate and update account_form = AccountForm(request.POST, instance=account) if account_form.is_valid(): account = account_form.save() return HttpResponseRedirect('/account') else: # Populate the form with the current account's data account_form = AccountForm(instance=account) # Pass back the form we have, after updating CSRF kargs.update(csrf(request)) context = RequestContext( request, dict(section="accounts", form=account_form, mode="update", account=account, **kargs)) return render_to_response("accounts/form.html", context)
def account_detail(request, account_id): """ Show details of a specific account. On GET, it will return details on the account numbered account_id. """ # Grab the account (or 404, of course) account = get_object_or_404(Account, pk=account_id) # Check that the user can access it, or 403 if not authenticate_account(request.user, account): raise PermissionDenied() # Get the transactions from or to this account transaction_list = Transaction.objects.filter( Q(from_acct=account) | Q(to_acct=account)) # Pass it back out to the renderer context = RequestContext( request, { "section": "accounts", "transactions": transaction_list, "account": account }) return render_to_response("accounts/detail.html", context)
def account_list(request): """ Render the listing of all accounts. On GET, it will return a listing of all accounts. """ # Recover the groups the accessor is in request_user = request.user account_list = Account.objects.all() return_list = [] # TODO: Figure out how to grab this without linear search for account in account_list: if authenticate_account(request_user, account): return_list.append(account) context = RequestContext(request, {"section":"accounts", "account_list":return_list}) return render_to_response("accounts/list.html", context)
def account_list(request): """ Render the listing of all accounts. On GET, it will return a listing of all accounts. """ # Recover the groups the accessor is in request_user = request.user account_list = Account.objects.all() return_list = [] # TODO: Figure out how to grab this without linear search for account in account_list: if authenticate_account(request_user, account): return_list.append(account) context = RequestContext(request, { "section": "accounts", "account_list": return_list }) return render_to_response("accounts/list.html", context)
def account_detail(request, account_id): """ Show details of a specific account. On GET, it will return details on the account numbered account_id. """ # Grab the account (or 404, of course) account = get_object_or_404(Account, pk=account_id) # Check that the user can access it, or 403 if not authenticate_account(request.user, account): raise PermissionDenied() # Get the transactions from or to this account transaction_list = Transaction.objects.filter( Q(from_acct=account) | Q(to_acct=account) ) # Pass it back out to the renderer context = RequestContext(request, {"section":"accounts", "transactions":transaction_list, "account":account}) return render_to_response("accounts/detail.html", context)