Profile tags

This commit is contained in:
Michał Gdula 2023-06-25 14:33:27 +00:00
parent 55940598ee
commit 2b5daa78b7
5 changed files with 54 additions and 25 deletions

View file

@ -1,7 +1,7 @@
from flask import Blueprint, request, render_template, abort
from sqlalchemy import func
from .models import Scores, Users
from .models import Scores, Users, TagJunction, Tags
from .config import GAME_VERSION, MAX_TOP_SCORES
from .extensions import db
@ -15,6 +15,7 @@ def index():
ver_arg = request.args.get("ver", GAME_VERSION).strip()
user_arg = request.args.get("user", "").strip()
user = None
tags = None
scores = db.session.query(Scores).filter_by(difficulty=diff_arg)
@ -33,6 +34,13 @@ def index():
)
else:
user = Users.query.filter_by(username=user_arg).first()
# get all tags from the junction table and add them to a list of tags
tags = (
db.session.query(Tags)
.join(TagJunction)
.filter(TagJunction.user_id == user.id)
.all()
)
if user:
scores = scores.filter_by(user_id=user.id)
else:
@ -41,7 +49,7 @@ def index():
scores = scores.order_by(Scores.score.asc()).limit(MAX_TOP_SCORES).all()
return render_template(
"views/scores.html", scores=scores, diff=int(diff_arg), ver=ver_arg, user=user
"views/scores.html", scores=scores, diff=int(diff_arg), ver=ver_arg, user=user, tags=tags
)