diff --git a/files/helpers/get.py b/files/helpers/get.py index f80e2dc46..b2df1f5a7 100644 --- a/files/helpers/get.py +++ b/files/helpers/get.py @@ -33,7 +33,7 @@ def get_id(username, graceful=False): return user[0] -def get_user(username, v=None, graceful=False, include_blocks=False, id_only=False): +def get_user(username, v=None, graceful=False, include_blocks=False, attributes=None): if not username: if graceful: return None abort(400, "Empty username.") @@ -42,7 +42,7 @@ def get_user(username, v=None, graceful=False, include_blocks=False, id_only=Fal if not username: if graceful: return None abort(400, "Empty username.") -\ + user = g.db.query( User ).filter( @@ -53,8 +53,8 @@ def get_user(username, v=None, graceful=False, include_blocks=False, id_only=Fal ) ) - if id_only: - user = user.options(load_only(User.id)) + if attributes: + user = user.options(load_only(*attributes)) user = user.one_or_none() diff --git a/files/routes/users.py b/files/routes/users.py index 89009677e..eba5b7877 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -156,7 +156,7 @@ def upvoters_downvoters(v, username, username2, cls, vote_cls, vote_dir, templat if not u.is_visible_to(v): abort(403) id = u.id - uid = get_user(username2, id_only=True).id + uid = get_user(username2, attributes=[User.id]).id page = get_page() @@ -219,7 +219,7 @@ def upvoting_downvoting(v, username, username2, cls, vote_cls, vote_dir, templat if not u.is_visible_to(v): abort(403) id = u.id - uid = get_user(username2, id_only=True).id + uid = get_user(username2, attributes=[User.id]).id page = get_page() @@ -522,10 +522,13 @@ def leaderboard_cached(v): def leaderboard(v): return render_template("leaderboard.html", v=v, leaderboard_cached=leaderboard_cached(v)) -@app.get("//css") +@app.get("/@/css") @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) -def get_css(id): - css, bg = g.db.query(User.css, User.background).filter_by(id=id).one_or_none() +def get_css(username): + user = get_user(username, attributes=[User.css, User.background]) + + css = user.css + bg = user.background if bg: if not css: css = '' @@ -543,10 +546,13 @@ def get_css(id): resp.headers["Content-Type"] = "text/css" return resp -@app.get("//profilecss") +@app.get("/@/profilecss") @limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) -def get_profilecss(id): - css, bg = g.db.query(User.profilecss, User.profile_background).filter_by(id=id).one_or_none() +def get_profilecss(username): + user = get_user(username, attributes=[User.profilecss, User.profile_background]) + + css = user.profilecss + bg = user.profile_background if bg: if not css: css = '' diff --git a/files/templates/userpage/userpage.html b/files/templates/userpage/userpage.html index 940b3a79c..f9a436023 100644 --- a/files/templates/userpage/userpage.html +++ b/files/templates/userpage/userpage.html @@ -6,7 +6,7 @@ {% endif %} {% if u and (u.profilecss or u.profile_background) and not request.values.get('nocss') and u.can_see_my_shit %} - + {% endif %} {% endblock %} {% block content %} diff --git a/files/templates/util/html_head.html b/files/templates/util/html_head.html index 95e723ec8..7b2728905 100644 --- a/files/templates/util/html_head.html +++ b/files/templates/util/html_head.html @@ -109,7 +109,7 @@ {% endif %} {% if (v.css or v.background) and not request.path.startswith('/settings') %} - + {% endif %} {% if v.themecolor == '30409f' %}