Enx777
Enx777

Reputation: 1

Sell on Finance "can't check until a frown turns upside down"

I'm working with finance cs50, and I don't understand why the error "can't check until a frown turns upside down" appears in the sales part, even if when i run flask the program works. If you kindly could help me, thanks.. :| sell page has all required elements can't check until a frown turns upside down :| sell handles invalid number of shares can't check until a frown turns upside down :| sell handles valid sale can't check until a frown turns upside down

sell.html page


{% block title %}
    Sell
{% endblock %}

{% block main %}
    <h1>Sell</h1>
    <form action="/sell" method="post">
        <div class="mb-3">
            <select name="symbol">
                {% for symbol in symbols %}
                    <option>{{ symbol["symbol"] }}</option>
                {% endfor %}
            </select>
        </div>
        <div class="mb-3">
            <input autocomplete="off" autofocus class="form-control mx-auto w-auto" name="shares" placeholder="Shares" type="number">
        </div>
        <button class="btn btn-primary" type="submit">Sell</button>
    </form>
{% endblock %}

"""Sell shares of stock"""
    # Get method
    if request.method == "GET":
        # Get the symbols
        user_id = session["user_id"]
        symbols = db.execute("SELECT symbol FROM transactions WHERE user_id = ? GROUP BY symbol", user_id)
        return render_template("sell.html", symbols=symbols)

    # Post method
    else:
        # Getting data from the form
        user_id = session["user_id"]
        symbol = request.form.get("symbol")
        shares = request.form.get("shares")

        # Check if theres no input
        if not symbol:
            return apology("Enter Symbol")

        # Check for positive integer input
        try:
            shares = int(request.form.get("shares"))
        except:
            return apology("Enter positive Integer")
        if shares <= 0:
            return apology("Enter positive Integer")

        # Check for shares
        price_ = lookup(symbol)["price"]
        total_price = shares * price_
        owned_shares = db.execute("SELECT shares FROM transactions WHERE user_id = ? AND symbol = ? GROUP BY symbol", user_id, symbol)[0]["shares"]

        if owned_shares < shares:
            return apology("Not enough shares")

        # Update users table
        current_cash = db.execute("SELECT cash FROM users WHERE id = ?", user_id)[0]["cash"]
        db.execute("UPDATE users SET cash = ? WHERE id = ?", current_cash + total_price, user_id)

        # Update transaction table
        date = datetime.datetime.now()
        db.execute("INSERT INTO transactions (user_id, symbol, shares, price, date) VALUES 
       (?, ?,?, ?, ?)",
        user_id, symbol, (-1)*shares, price_, date)
        flash("Sold!")
        return redirect("/")```

Upvotes: 0

Views: 3433

Answers (1)

Pedro Carib&#233;
Pedro Carib&#233;

Reputation: 270

The ':|' check means that all previous failed checks need to be resolved before proceeding to the next ones.

In the example below, the logging issue needs to be resolved before check50 proceeds with it's checks:

enter image description here

Upvotes: 0

Related Questions