def task_one_trans_report(request,account_id=None): account = Account.get_by_id(int(account_id)) if account is None: raise Http404 logging.info('do_one_trans_report(%s)' % (account_id)) account_report = getDetailAccountReport(account.key().id()) logging.info('account report: "%s"' % account_report) send_mail_to_user('VMTracker account id:%d report' % int(account_id), account_report, account.report_email) return HttpResponse('ok')
def account_edit(request, account_id): account = Account.get_by_id(int(account_id)) if account is None: raise Http404 if request.method == 'POST': form = AccountForm(request.POST, instance=account) if form.is_valid(): logging.info('edit account before - id: %s key: %s data: %s' % (account.key().id() , account.key(), account)) form.save(commit=False) logging.info('edit account after - id: %s key: %s data: %s' % (account.key().id() , account.key(), account)) account.save() return redirect('/accounts/') else: form = AccountForm(instance=account) return render_to_response('accounts/edit.html', RequestContext(request, { 'form': form }))
def transaction_create(request, account_id): account = Account.get_by_id(int(account_id)) if account is None: raise Http404 if request.method == 'POST': t = Transaction(parent=account) form = TransactionForm(request.POST, instance=t) if form.is_valid(): form.save(commit=False) t.setDate() t.save() logging.info('new transaction created - id: %s key: %s data: %s' % (t.key().id() , t.key(), t)) return redirect('/accounts/'+account_id+'/transactions/') else: form = TransactionForm() return render_to_response('accounts/transaction_create.html', RequestContext(request, { 'form':form }))
def getDetailAccountReport(account_id=None): if not account_id: return 'no account id' report = 'account detail report (account_id: %d, time: %s)\n' % (account_id, datetime.datetime.utcnow()) account = Account.get_by_id(int(account_id)) if account is None: report = report + 'account id:%d not found' % account_id return report report = report + '\nAccount:\n' report = report + account.getReportInfo() report = report + '\n\nLast 10 transactions: [id;date;amount;desc]\n' transaction_list = Transaction.objects.all().ancestor(account).order('-create_date').fetch(10) for transaction in transaction_list: report = report + transaction.getReportInfo() + '\n' return report
def transaction_list(request, account_id): account = Account.get_by_id(int(account_id)) if account is None: raise Http404 transaction_list = Transaction.objects.all().ancestor(account).order('-create_date').fetch(100) return render_to_response('accounts/transaction_list.html', RequestContext(request,{ 'transaction_list': transaction_list, 'account': account}))
def account_show(request,account_id): account = Account.get_by_id(int(account_id)) if account is None: raise Http404 return render_to_response('accounts/show.html', RequestContext( request, { 'account': account }))