def __edit_get_loan(loan_id, our_loans, loan, current_user_id):

    our_accounts = Accounts(current_user_id)

    if request.method == 'POST': # POST

        dict = __validate_get_loan_form()
        for key in dict.keys(): exec(key + " = dict['" + key + "']")

        # 'heavier' checks
        if not error:
            # valid amount?
            if is_float(amount):
                # valid date?
                if is_date(date):
                    # valid account?
                    if our_accounts.is_account(account_id=credit_to_account):

                        their_accounts = Accounts(loan.other_user)

                        # first roll back user balances
                        our_accounts.modify_user_balance(account_id=loan.account, amount=-float(loan.amount))
                        their_accounts.modify_user_balance(amount=loan.amount)

                        # now roll back loan account monies
                        our_accounts.modify_loan_balance(amount=loan.amount, with_user_id=loan.other_user)
                        their_accounts.modify_loan_balance(amount=-float(loan.amount), with_user_id=current_user_id)

                        # the user might have changed...
                        if loan.other_user != from_user:
                            their_accounts = Accounts(from_user)

                        # transfer money from/to respective accounts
                        our_accounts.modify_user_balance(account_id=credit_to_account, amount=amount)
                        their_accounts.modify_user_balance(amount=-float(amount))

                        # fudge loan 'account' monies
                        our_accounts.modify_loan_balance(amount=-float(amount), with_user_id=from_user)
                        their_accounts.modify_loan_balance(amount=amount, with_user_id=current_user_id)

                        # get slug as a unique identifier
                        slug = our_loans.get_loan_slug(loan_id=loan_id)

                        # the user might have changed...
                        their_loans = Loans(loan.other_user)
                        if loan.other_user != from_user:
                            # delete their original loan entry (and its slug)
                            their_loans.delete_loan(slug=slug)

                            # new user
                            their_loans = Loans(from_user)
                            their_loan_id = their_loans.add_loan(other_user_id=current_user_id, date=date,
                                                                 description=description, amount=-float(amount))

                            # save their new slug
                            their_slugs = Slugs(from_user)
                            their_slugs.add_slug(type='loan', object_id=their_loan_id, slug=slug)
                        else:
                            # update their loans entry
                            their_loans.edit_loan(other_user_id=current_user_id, date=date, description=description,
                                                  amount=amount, slug=slug)

                        # update our loans entry
                        our_loans.edit_loan(other_user_id=from_user, date=date, description=description,
                                              amount=amount, account_id=credit_to_account, loan_id=loan_id)

                        flash('Loan edited')

                    else: error = 'Not a valid target account'
                else: error = 'Not a valid date'
            else: error = 'Not a valid amount'

    our_users = Users(current_user_id)
    users = our_users.get_connections()
    accounts = our_accounts.get_accounts()

    return render_template('admin_edit_get_loan.html', **locals())
Editing of loan entries where we were getting money
dataset/ETHPy150Open radekstepan/FlaskBudget/presenters/loans.py/__edit_get_loan