mirror of
https://github.com/Fluffy-Bean/GameExpo23.git
synced 2025-05-14 14:22:16 +00:00
Profile tags
This commit is contained in:
parent
55940598ee
commit
2b5daa78b7
5 changed files with 54 additions and 25 deletions
|
@ -14,7 +14,7 @@ from .config import (
|
|||
UPLOAD_DIR,
|
||||
UPLOAD_RESOLUTION,
|
||||
)
|
||||
from .models import Users, Sessions, Scores, ProfileTags, PasswordReset
|
||||
from .models import Users, Sessions, Scores
|
||||
from .extensions import db
|
||||
|
||||
|
||||
|
@ -175,8 +175,6 @@ def post_delete_account():
|
|||
|
||||
db.session.query(Sessions).filter_by(user_id=current_user.id).delete()
|
||||
db.session.query(Scores).filter_by(user_id=current_user.id).delete()
|
||||
db.session.query(ProfileTags).filter_by(user_id=current_user.id).delete()
|
||||
db.session.query(PasswordReset).filter_by(user_id=current_user.id).delete()
|
||||
db.session.delete(user)
|
||||
db.session.commit()
|
||||
|
||||
|
|
|
@ -55,32 +55,28 @@ class Sessions(db.Model):
|
|||
)
|
||||
|
||||
|
||||
class PasswordReset(db.Model):
|
||||
class TagJunction(db.Model):
|
||||
"""
|
||||
Password reset table
|
||||
Tag Junction table
|
||||
"""
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
||||
user_id = db.Column(db.Integer, db.ForeignKey("users.id", use_alter=True))
|
||||
|
||||
reset_key = db.Column(db.String, nullable=False, unique=True)
|
||||
|
||||
created_at = db.Column(
|
||||
db.DateTime,
|
||||
nullable=False,
|
||||
server_default=db.func.now(),
|
||||
)
|
||||
tag_id = db.Column(db.Integer, db.ForeignKey("tags.id", use_alter=True))
|
||||
|
||||
|
||||
class ProfileTags(db.Model):
|
||||
class Tags(db.Model):
|
||||
"""
|
||||
Profile Tags table
|
||||
"""
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
user_id = db.Column(db.Integer, db.ForeignKey("users.id", use_alter=True))
|
||||
users = db.relationship("TagJunction", backref=db.backref("tags", lazy=True))
|
||||
|
||||
tag = db.Column(db.String, nullable=False)
|
||||
icon = db.Column(db.String)
|
||||
color = db.Column(db.String)
|
||||
|
||||
|
||||
class Users(db.Model, UserMixin):
|
||||
|
@ -106,8 +102,7 @@ class Users(db.Model, UserMixin):
|
|||
|
||||
scores = db.relationship("Scores", backref=db.backref("users", lazy=True))
|
||||
tokens = db.relationship("Sessions", backref=db.backref("users", lazy=True))
|
||||
reset = db.relationship("PasswordReset", backref=db.backref("users", lazy=True))
|
||||
tags = db.relationship("ProfileTags", backref=db.backref("users", lazy=True))
|
||||
tags = db.relationship("TagJunction", backref=db.backref("users", lazy=True))
|
||||
|
||||
def get_id(self):
|
||||
return str(self.alt_id)
|
||||
|
|
|
@ -60,11 +60,6 @@
|
|||
|
||||
gap: 0.5rem
|
||||
|
||||
h2
|
||||
margin: 0
|
||||
font-size: 1.3rem
|
||||
color: RGB($white)
|
||||
|
||||
p
|
||||
margin: 0
|
||||
font-size: 1rem
|
||||
|
@ -76,6 +71,32 @@
|
|||
border: 0 solid transparent
|
||||
border-bottom: 1px solid RGBA($white, 0.1)
|
||||
|
||||
.profile-title
|
||||
display: flex
|
||||
flex-direction: row
|
||||
gap: 0.5rem
|
||||
|
||||
h2
|
||||
margin: 0
|
||||
font-size: 1.3rem
|
||||
color: RGB($white)
|
||||
|
||||
.profile-tag
|
||||
margin: auto 0
|
||||
padding: 0.2rem
|
||||
|
||||
font-size: 0.7rem
|
||||
|
||||
color: RGB($black)
|
||||
background-color: RGB($white)
|
||||
border-radius: 2px
|
||||
|
||||
> img
|
||||
width: 0.9rem
|
||||
height: 0.9rem
|
||||
margin-right: 0.2rem
|
||||
|
||||
|
||||
@media (max-width: 621px)
|
||||
.account-block
|
||||
flex-direction: column
|
||||
|
|
|
@ -43,7 +43,14 @@
|
|||
<img src="{{ url_for('static', filename='images/pfp.png') }}" alt="Profile picture">
|
||||
{% endif %}
|
||||
<div class="other">
|
||||
<div class="profile-title">
|
||||
<h2>{{ user.username }}</h2>
|
||||
{% for tag in tags %}
|
||||
<span class="profile-tag" style="background-color:{{ tag.color }};">
|
||||
{{ tag.tag }}
|
||||
</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<hr>
|
||||
<p>Joined {{ user.joined_at|timesince }}</p>
|
||||
</div>
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue