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
|
min-width: 6rem
|
||||||
|
|
||||||
text-decoration: none
|
text-decoration: none
|
||||||
|
text-align: end
|
||||||
white-space: nowrap
|
white-space: nowrap
|
||||||
font-size: 0.9em
|
font-size: 0.9em
|
||||||
|
|
||||||
|
|
|
@ -5,15 +5,15 @@
|
||||||
|
|
||||||
.picture
|
.picture
|
||||||
margin: 0
|
margin: 0
|
||||||
width: 13rem
|
width: 10rem
|
||||||
|
|
||||||
position: relative
|
position: relative
|
||||||
display: flex
|
display: flex
|
||||||
flex-direction: column
|
flex-direction: column
|
||||||
|
|
||||||
> img
|
> img
|
||||||
height: 13rem
|
height: 10rem
|
||||||
width: 13rem
|
width: 10rem
|
||||||
|
|
||||||
object-fit: cover
|
object-fit: cover
|
||||||
|
|
||||||
|
@ -65,3 +65,15 @@
|
||||||
flex-direction: column
|
flex-direction: column
|
||||||
justify-content: flex-start
|
justify-content: flex-start
|
||||||
gap: 0.5rem
|
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 flask import Blueprint, request, render_template, abort
|
||||||
|
from sqlalchemy import func
|
||||||
|
|
||||||
from .models import Scores, Users
|
from .models import Scores, Users
|
||||||
from .config import GAME_VERSION, MAX_TOP_SCORES
|
from .config import GAME_VERSION, MAX_TOP_SCORES
|
||||||
|
from .extensions import db
|
||||||
|
|
||||||
|
|
||||||
blueprint = Blueprint("views", __name__)
|
blueprint = Blueprint("views", __name__)
|
||||||
|
@ -12,18 +15,29 @@ def index():
|
||||||
ver_arg = request.args.get("ver", GAME_VERSION)
|
ver_arg = request.args.get("ver", GAME_VERSION)
|
||||||
user_arg = request.args.get("user", None)
|
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:
|
if ver_arg:
|
||||||
scores = scores.filter_by(version=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():
|
if user := Users.query.filter_by(username=user_arg).first():
|
||||||
scores = scores.filter_by(user_id=user.id)
|
scores = scores.filter_by(user_id=user.id)
|
||||||
print(user.id)
|
|
||||||
else:
|
else:
|
||||||
abort(404, "User not found")
|
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(
|
return render_template(
|
||||||
"views/scores.html",
|
"views/scores.html",
|
||||||
|
|
Loading…
Add table
Reference in a new issue