mirror of
https://github.com/Fluffy-Bean/GameExpo23.git
synced 2025-05-14 14:22:16 +00:00
Show user only once on top scores
This commit is contained in:
parent
e08b31a430
commit
e1d22d502d
3 changed files with 34 additions and 7 deletions
|
@ -51,6 +51,7 @@
|
|||
min-width: 6rem
|
||||
|
||||
text-decoration: none
|
||||
text-align: end
|
||||
white-space: nowrap
|
||||
font-size: 0.9em
|
||||
|
||||
|
|
|
@ -5,15 +5,15 @@
|
|||
|
||||
.picture
|
||||
margin: 0
|
||||
width: 13rem
|
||||
width: 10rem
|
||||
|
||||
position: relative
|
||||
display: flex
|
||||
flex-direction: column
|
||||
|
||||
> img
|
||||
height: 13rem
|
||||
width: 13rem
|
||||
height: 10rem
|
||||
width: 10rem
|
||||
|
||||
object-fit: cover
|
||||
|
||||
|
@ -65,3 +65,15 @@
|
|||
flex-direction: column
|
||||
justify-content: flex-start
|
||||
gap: 0.5rem
|
||||
@media (max-width: 621px)
|
||||
.profile-settings
|
||||
flex-direction: column
|
||||
gap: 1rem
|
||||
|
||||
.picture
|
||||
margin: 0 auto
|
||||
width: 13rem
|
||||
|
||||
> img
|
||||
height: 13rem
|
||||
width: 13rem
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
from flask import Blueprint, request, render_template, abort
|
||||
from sqlalchemy import func
|
||||
|
||||
from .models import Scores, Users
|
||||
from .config import GAME_VERSION, MAX_TOP_SCORES
|
||||
from .extensions import db
|
||||
|
||||
|
||||
blueprint = Blueprint("views", __name__)
|
||||
|
@ -12,18 +15,29 @@ def index():
|
|||
ver_arg = request.args.get("ver", GAME_VERSION)
|
||||
user_arg = request.args.get("user", None)
|
||||
|
||||
scores = Scores.query.filter_by(difficulty=diff_arg).order_by(Scores.score.asc())
|
||||
scores = db.session.query(Scores).filter_by(difficulty=diff_arg)
|
||||
|
||||
subquery = (
|
||||
db.session.query(Scores.user_id, func.min(Scores.score).label('min'))
|
||||
.group_by(Scores.user_id)
|
||||
.subquery()
|
||||
)
|
||||
|
||||
if ver_arg:
|
||||
scores = scores.filter_by(version=ver_arg)
|
||||
if user_arg:
|
||||
|
||||
if not user_arg:
|
||||
scores = (
|
||||
scores.join(subquery, Scores.user_id == subquery.c.user_id)
|
||||
.filter(Scores.score == subquery.c.min)
|
||||
)
|
||||
else:
|
||||
if user := Users.query.filter_by(username=user_arg).first():
|
||||
scores = scores.filter_by(user_id=user.id)
|
||||
print(user.id)
|
||||
else:
|
||||
abort(404, "User not found")
|
||||
|
||||
scores = scores.limit(MAX_TOP_SCORES).all()
|
||||
scores = scores.order_by(Scores.score.asc()).limit(MAX_TOP_SCORES).all()
|
||||
|
||||
return render_template(
|
||||
"views/scores.html",
|
||||
|
|
Loading…
Add table
Reference in a new issue