Esempio n. 1
0
def balance(request):
    account = request.user
    operation = Operation(account=account, amount=0, success=True, category='balance')
    res = [
        'Account: %s' % account.id,
        'Balance: %d' % account.balance,
        'Current time: %s' % datetime.now().strftime("%d-%m-%Y %H:%M:%S")
    ]
    operation.save()
    return render(request, 'info.html', {'messages': res, 'title': 'Balance'})
Esempio n. 2
0
def get_cash(request):
    amount = int(request.POST.get('amount', 0))
    account = request.user
    if amount <= account.balance:
        account.balance -= amount
        operation = Operation(account=account, amount=amount, success=True, category='cash')
        account.save()
        operation.save()
        messages = [
            'Operation successful',
            'Amount: %d' % amount,
            'Balance: %d' % account.balance,
            'Time: %s' % operation.date.strftime("%d-%m-%Y %H:%M:%S")
        ]
        title = 'Cash'
    else:
        operation = Operation(account=account, amount=0, success=False, category='cash')
        operation.save()
        messages = [
            'Error: Insufficient funds',
            'Amount: 0',
            'Balance: %d' % account.balance,
            'Time: %s' % operation.date.strftime("%d-%m-%Y %H:%M:%S")
        ]
        title = 'Error'
    operation.save()
    return render(request, 'info.html', {'messages': messages, 'title': title})