Ejemplo n.º 1
0
def show_balance():
    # In session (user signed in) and username is admin
    if "username" in session and session["username"] == "admin":
        # GET request
        if request.method == "GET":
            return render_template("admin-balance.html", \
                  title="Balance", \
                  username="******")
        # POST request
        else:
            # Accesses current form data (data transmitted in a POST request).
            username = request.form["username"]
            # Attempts to get the balance of the user with the given username.
            balance = model.get_balance(username)
            # If balance is a float.
            if isinstance(balance, float):
                response = [format(balance, ".2f")]
            # If balance is an error message.
            else:
                response = balance
            return render_template("admin-balance.html", \
                  title="Balance", \
                  username="******", \
                  user=username, \
                  response=response)
    # Out of session (user not signed in)
    else:
        return redirect(url_for("signup.show_signup"))
Ejemplo n.º 2
0
def show_portfolio():
    # In session (user signed in) and username is admin
    if "username" in session and session["username"] == "admin":
        # GET request
        if request.method == "GET":
            return render_template("admin-portfolio.html", \
                  title="Portfolio", \
                  username="******")
        # POST request
        else:
            # Accesses current form data (data transmitted in a POST request).
            username = request.form["username"]
            balance = model.get_balance(username)
            earnings = model.get_earnings(username)
            total = float(balance) + float(earnings)
            portfolio = model.get_holdings_dataframe(username)
            return render_template("admin-portfolio-user.html", \
                  title="Portfolio", \
                  username="******", \
                  user=username, \
                  balance=format(balance, ".2f"), \
                  earnings=format(earnings, ".2f"), \
                  total=format(total, ".2f"), \
                  portfolio=portfolio)
    # Out of session (user not signed in)
    else:
        return redirect(url_for("signup.show_signup"))
Ejemplo n.º 3
0
def show_balance():
    # In session (user signed in)
    if "username" in session:
        # User
        if session["username"] != "admin":
            return render_template("balance.html", \
                   title="Balance", \
                   username=session["username"], \
                   balance=format(model.get_balance(session["username"]), ".2f"))
        # Admin
        else:
            return redirect(url_for("admin.show_dashboard"))
    # Out of session (user not signed in)
    else:
        return redirect(url_for("signup.show_signup"))
Ejemplo n.º 4
0
def show_withdraw():
    # In session (user signed in) and username is admin
    if "username" in session and session["username"] == "admin":
        # GET request
        if request.method == "GET":
            return render_template("admin-withdraw.html", \
                  title="Withdraw", \
                  username="******")
        # POST request
        else:
            # Accesses current form data (data transmitted in a POST request).
            username = request.form["username"]
            amount = request.form["amount"]
            # Attempts to get the balance of the user with the given username.
            balance = model.get_balance(username)
            # If balance is a float.
            if isinstance(balance, float):
                # Saves the user's old (current) balance.
                old_balance = format(balance, ".2f")
                # Attempts to calculate the new balance.
                new_balance = model.calculate_new_withdraw(balance, amount)
                # If new_balance is a float.
                if isinstance(new_balance, float):
                    response = [format(new_balance, ".2f")]
                    # Updates the user's balance in the database.
                    model.update_balance(new_balance, username)
                # If new_balance is an error message.
                else:
                    response = new_balance
            # If balance is an error message.
            else:
                old_balance = None
                response = balance
            return render_template("admin-withdraw.html", \
                  title="Withdraw", \
                  username="******", \
                  user=username, \
                  old_balance=old_balance, \
                  response=response)
    # Out of session (user not signed in)
    else:
        return redirect(url_for("signup.show_signup"))
Ejemplo n.º 5
0
def show_portfolio():
    # In session (user signed in)
    if "username" in session:
        # User
        if session["username"] != "admin":
            balance = model.get_balance(session["username"])
            earnings = model.get_earnings(session["username"])
            total = float(balance) + float(earnings)
            portfolio = model.get_holdings_dataframe(session["username"])
            return render_template("portfolio.html", \
                  title="Portfolio", \
                  username=session["username"], \
                  balance=format(balance, ".2f"), \
                  earnings=format(earnings, ".2f"), \
                  total=format(total, ".2f"), \
                  portfolio=portfolio)
        # Admin
        else:
            return redirect(url_for("admin.show_dashboard"))
    # Out of session (user not signed in)
    else:
        return redirect(url_for("signup.show_signup"))