more intuitive css urls for easier css sharing
parent
71185a94ca
commit
6ee03f143b
|
@ -33,7 +33,7 @@ def get_id(username, graceful=False):
|
||||||
|
|
||||||
return user[0]
|
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 not username:
|
||||||
if graceful: return None
|
if graceful: return None
|
||||||
abort(400, "Empty username.")
|
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 not username:
|
||||||
if graceful: return None
|
if graceful: return None
|
||||||
abort(400, "Empty username.")
|
abort(400, "Empty username.")
|
||||||
\
|
|
||||||
user = g.db.query(
|
user = g.db.query(
|
||||||
User
|
User
|
||||||
).filter(
|
).filter(
|
||||||
|
@ -53,8 +53,8 @@ def get_user(username, v=None, graceful=False, include_blocks=False, id_only=Fal
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if id_only:
|
if attributes:
|
||||||
user = user.options(load_only(User.id))
|
user = user.options(load_only(*attributes))
|
||||||
|
|
||||||
user = user.one_or_none()
|
user = user.one_or_none()
|
||||||
|
|
||||||
|
|
|
@ -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)
|
if not u.is_visible_to(v): abort(403)
|
||||||
id = u.id
|
id = u.id
|
||||||
|
|
||||||
uid = get_user(username2, id_only=True).id
|
uid = get_user(username2, attributes=[User.id]).id
|
||||||
|
|
||||||
page = get_page()
|
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)
|
if not u.is_visible_to(v): abort(403)
|
||||||
id = u.id
|
id = u.id
|
||||||
|
|
||||||
uid = get_user(username2, id_only=True).id
|
uid = get_user(username2, attributes=[User.id]).id
|
||||||
|
|
||||||
page = get_page()
|
page = get_page()
|
||||||
|
|
||||||
|
@ -522,10 +522,13 @@ def leaderboard_cached(v):
|
||||||
def leaderboard(v):
|
def leaderboard(v):
|
||||||
return render_template("leaderboard.html", v=v, leaderboard_cached=leaderboard_cached(v))
|
return render_template("leaderboard.html", v=v, leaderboard_cached=leaderboard_cached(v))
|
||||||
|
|
||||||
@app.get("/<int:id>/css")
|
@app.get("/@<username>/css")
|
||||||
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
||||||
def get_css(id):
|
def get_css(username):
|
||||||
css, bg = g.db.query(User.css, User.background).filter_by(id=id).one_or_none()
|
user = get_user(username, attributes=[User.css, User.background])
|
||||||
|
|
||||||
|
css = user.css
|
||||||
|
bg = user.background
|
||||||
|
|
||||||
if bg:
|
if bg:
|
||||||
if not css: css = ''
|
if not css: css = ''
|
||||||
|
@ -543,10 +546,13 @@ def get_css(id):
|
||||||
resp.headers["Content-Type"] = "text/css"
|
resp.headers["Content-Type"] = "text/css"
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
@app.get("/<int:id>/profilecss")
|
@app.get("/@<username>/profilecss")
|
||||||
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
||||||
def get_profilecss(id):
|
def get_profilecss(username):
|
||||||
css, bg = g.db.query(User.profilecss, User.profile_background).filter_by(id=id).one_or_none()
|
user = get_user(username, attributes=[User.profilecss, User.profile_background])
|
||||||
|
|
||||||
|
css = user.profilecss
|
||||||
|
bg = user.profile_background
|
||||||
|
|
||||||
if bg:
|
if bg:
|
||||||
if not css: css = ''
|
if not css: css = ''
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<link rel="stylesheet" href="{{('css/transparent.css') | asset}}">
|
<link rel="stylesheet" href="{{('css/transparent.css') | asset}}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if u and (u.profilecss or u.profile_background) and not request.values.get('nocss') and u.can_see_my_shit %}
|
{% if u and (u.profilecss or u.profile_background) and not request.values.get('nocss') and u.can_see_my_shit %}
|
||||||
<link rel="stylesheet" href="/{{u.id}}/profilecss">
|
<link rel="stylesheet" href="/@{{u.username}}/profilecss">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
|
@ -109,7 +109,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<link rel="stylesheet" href="{{('css/'~v.theme~'.css') | asset}}">
|
<link rel="stylesheet" href="{{('css/'~v.theme~'.css') | asset}}">
|
||||||
{% if (v.css or v.background) and not request.path.startswith('/settings') %}
|
{% if (v.css or v.background) and not request.path.startswith('/settings') %}
|
||||||
<link rel="stylesheet" href="/{{v.id}}/css">
|
<link rel="stylesheet" href="/@{{v.username}}/css">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if v.themecolor == '30409f' %}
|
{% if v.themecolor == '30409f' %}
|
||||||
<link rel="stylesheet" href="{{('css/30409f.css') | asset}}">
|
<link rel="stylesheet" href="{{('css/30409f.css') | asset}}">
|
||||||
|
|
Loading…
Reference in New Issue