def save_added_bank_account(): """Add a bank account and send it to db, user can view it after being redirected back to the overview page.""" if session.get('user_id'): submit_add_account_form = request.form.get("submit_add_account_form") if submit_add_account_form == 'Submit': account_id = request.form.get("account_name") name = request.form.get("account_name") available_balance = request.form.get("available_balance") type = "depository" user = crud.get_user_by_user_id( session['user_id']) #gets user by session user_id crud.create_account(account_id, available_balance, type, name, user) flash('New bank account Has Been added!') return redirect('/overview') else: flash('Sorry, something went wrong. Please try again.') return redirect('/add_account') else: flash('Please login to proceed to this page.') return redirect('/login')
def create_account(): """Create an account.""" account_type = request.form.get("account_type") account_nickname = request.form.get("account_nickname") crud.create_account(user_id=session['user_id'], account_type=account_type, account_nickname=account_nickname) return redirect("/profile")
def mock_data(): """Create sample data for testing.""" crud.create_user("Johnny", "John", "johnny@john", "john123") crud.create_user("Jane", "Doe", "jane@doe", "jane123") crud.create_user("Randomly", "Random", "randomly@random", "randomly123") crud.create_user("Honey", "Dew", "honey@dew", "honey123") crud.create_account(1, "Saving", "testing1") crud.create_account(2, "Checking", "testing2") crud.create_account(3, "Other", "testing3") n = datetime.date.today() future_date = datetime.date.today() + datetime.timedelta(120) crud.create_entry_log(1, n, "Income", "testing1: x1", 500) crud.create_entry_log(2, n, "Income", "testing2: with q20Days", 1000, future_date, datetime.timedelta(20)) crud.create_entry_log(3, n, "Expense", "desc-testing3", -500)
user_db = crud.create_user(username, password) users_in_db.append(user_db) login_in_db = [] for login in user_data: user_id = choice(users_in_db).id login_db = crud.create_login(user_id) login_in_db.append(login_db) account_in_db = [] for account in account_data: email, password = (account['email'], account['password']) login_id = choice(login_in_db).id account_db = crud.create_account(email, password, login_id) account_in_db.append(account_db) lists_in_db = [] for newlist in list_data: name = (newlist['name']) user_id = choice(users_in_db).id list_db = crud.create_list(name, user_id) lists_in_db.append(list_db) entries_in_db = [] for entry in entry_data: user_text = (entry['user_text']) newlist_id = choice(lists_in_db).id entry_db = crud.create_entry(user_text, newlist_id)
for item in transaction_data['transactions']: merchant_name = (item['name']) db_merchant_name = crud.create_merchant_name(merchant_name, user) merchant_names_in_db.append(db_merchant_name) # Populate budget table in budgetapp db , LATER through user inputs. # Populate account table in budgetapp db for item in balances_data['accounts']: account_id, type, name = (item['account_id'], item['type'], item['name']) available_balance = (item['balances']['available']) crud.create_account(account_id, available_balance, type, name, user) # Populate transaction table in budgetapp db + store transactions in list transactions_in_db = [] for item in transaction_data['transactions']: amount, merchant_name, account_id = (item['amount'], item['name'], item['account_id']) date = datetime.strptime(item['date'], '%Y-%m-%d') db_transaction = crud.create_transaction(amount, date, merchant_name, user, account_id) transactions_in_db.append(db_transaction) #blocker: how to populate fk in transaction table when primary key wasn't autoincremented. What about category and acccount parameters?
last_name = f'Bobby{n}' email = f'test{n}@test.com' # A unique email! password = f'test{n}' crud.create_user(first_name, last_name, email, password) #* Miss Piggy *# crud.create_user("Miss", "Piggy", "*****@*****.**", "kermit") ### Seeding Account ### for n in range(1, 5): """Seeding accounts table for user_id 1.""" user_id = 1 account_type = "Checking" account_nickname = f"Nickname{n}" crud.create_account(user_id, account_type, account_nickname) for n in range(5, 9): """Seeding accounts table for user_id 2.""" user_id = 2 account_type = "Checking" account_nickname = f"Nickname{n}" crud.create_account(user_id, account_type, account_nickname) #@ Miss Piggy @# crud.create_account(11, "Checking", "Wedding Fund") # account id = 10 # crud.create_account(11, "Checking", "Shopping - Clothes") # crud.create_account(11, "Checking", "Shopping - Jewelries") # account id = 12 # crud.create_account(11, "Checking", "Shopping - MakeUp")