def new_comment_answer(answer_id): answer_database = queries.answer_by_id(answer_id) users_database = queries.select_all_users() return render_template('form_answer_comment.html', form="Comment", answer_database=answer_database, users_database=users_database)
def new_comment(questionid): id_num = questionid add_answer = True users_database = queries.select_all_users() question_database = queries.question_by_id(id_num) return render_template('form_new_answer.html', form="Comment", add_answer=add_answer, id_num=id_num, question_database=question_database, users_database=users_database)
def leaders(): """Show leader board""" users = q.select_all_users() leaders = [] for user in users: total = user.cash stocks = q.select_stocks_by_user(user.id) for stock in stocks: if stock.quantity > 0: price = h.lookup(stock.symbol)['price'] total += stock.quantity * price leaders.append([user.username, total]) leaders.sort(reverse=True, key=lambda x: x[1]) leaders = leaders[:10] for i in range(len(leaders)): leaders[i][1] = h.usd(leaders[i][1]) return render_template('leaders.html', leaders=leaders[:11])
from typing import List, TypedDict import queries # Although this type class is not necessary, # it helps to have these types here anyways. # If this type class is ever wrong, mypy will # rightfully complain. class User(TypedDict): id: int email: str nickname: str age: int is_admin: bool existing = queries.get_a_user_by_email(in1='*****@*****.**') if len(existing) == 0: queries.create_a_new_user(email='*****@*****.**', age=25, nickname='a', is_admin=False) users: List[User] = queries.select_all_users() print([user['id'] for user in users]) new_user = queries.get_a_user_by_email(in1='*****@*****.**')[0] print(new_user['nickname'])