Skip to content

Commit

Permalink
Fixed placement of elements and invalid value inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmatu committed Mar 6, 2022
1 parent d454c05 commit 9f8040f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
19 changes: 11 additions & 8 deletions routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ def logout():

@app.route("/mainpage", methods = ["POST", "GET"])
def mainpage():
if request.method == "GET":
if session.get("username"):
return scores.get_user_scores()
else:
return redirect("/mainpage/allstats")
if request.method == "POST":
scores.add_score()
return redirect("/")
if request.method == "GET":
if session.get("username"):
return scores.get_user_scores()
else:
return redirect("/mainpage/allstats")
if request.method == "POST":
if check_valid_score:
scores.add_score()
return redirect("/")
else:
return render_template("/mainpage", error="Invalid value(s) while adding score. Please try again.")

@app.route("/game/<int:id>", methods = ["GET"])
def match(id):
Expand Down
11 changes: 10 additions & 1 deletion scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ def add_score():
game_id = game.fetchone()[0]
sql = "INSERT INTO averages (game_id, average_date, user_id, average, tons, highest_score) VALUES (:game_id, current_date, :user_id, :average, :tons, :highest_score)"
db.session.execute(sql, {"game_id": game_id, "user_id": user_id, "average": average, "tons": tons, "highest_score": highest})
db.session.commit()
db.session.commit()

def check_valid_score():
if request.form["addaverage"] > 180:
return False
if request.form["addtons"] > 5:
return False
if request.form["addhighest"] > 180:
return False
return True
5 changes: 3 additions & 2 deletions templates/mainpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{% block title %}Main page{% endblock %}
{% block content %}
{% if session.username and "allstats" not in request.path %}
<p>{{ error }}</p>
<button style="margin-left: 25px;" class="btn btn-info" onclick="showScore()" id="bb">Add scores</button>
<div id="c">
<div class="container">
Expand All @@ -10,7 +11,7 @@
<br>
Highest score: <input class="input-group mb-3" style="font-family: sans-serif;" type="number" step="1" min=1 max=180 name="addhighest" required>
<br>
<div><span title="100+ scores with 3 darts" style="color: blue; cursor: default;">(?)</span> Ton+ count: <input class="input-group mb-3" style="font-family: sans-serif;" type="number" step="1" min=0 name="addtons" required></div>
<div><span title="100+ scores with 3 darts" style="color: blue; cursor: default;">(?)</span> Ton+ count: <input class="input-group mb-3" style="font-family: sans-serif;" type="number" step="1" min=0 max=5 name="addtons" required></div>
<br>
<input class="btn btn-info" type="submit" value="Submit">
</form>
Expand All @@ -34,8 +35,8 @@ <h2>Your averages:</h2>
{% endfor %}
</section>
{% else %}
{% if session.username and "allstats" in request.path %}
<section style="margin-left: 25px;">
{% if session.username and "allstats" in request.path %}
<h1>Stats from all users</h1>
{% else %}
{% endif %}
Expand Down

0 comments on commit 9f8040f

Please sign in to comment.