organize templates (#435)

dude file management lmao
remotes/1693176582716663532/tmp_refs/heads/watchparty
geese-suck 2022-11-08 22:11:46 -08:00 committed by GitHub
parent ffd9c73566
commit 462e3421b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 79 additions and 79 deletions

View File

@ -24,7 +24,7 @@ def settings(v):
@app.get("/settings/personal") @app.get("/settings/personal")
@auth_required @auth_required
def settings_personal(v): def settings_personal(v):
return render_template("settings_personal.html", v=v) return render_template("settings/personal.html", v=v)
@app.delete('/settings/background') @app.delete('/settings/background')
@limiter.limit("1/second;30/minute;200/hour;1000/day") @limiter.limit("1/second;30/minute;200/hour;1000/day")
@ -64,7 +64,7 @@ def settings_personal_post(v):
request_flag = int(time.time()) request_flag = int(time.time())
setattr(v, column_name, request_flag) setattr(v, column_name, request_flag)
if badge_id: badge_grant(v, badge_id) if badge_id: badge_grant(v, badge_id)
return render_template("settings_personal.html", v=v, msg=f"You have set the {friendly_name} permanently! Enjoy your new badge!") return render_template("settings/personal.html", v=v, msg=f"You have set the {friendly_name} permanently! Enjoy your new badge!")
elif current_value != request_flag: elif current_value != request_flag:
setattr(v, column_name, request_flag) setattr(v, column_name, request_flag)
return True return True
@ -134,38 +134,38 @@ def settings_personal_post(v):
v.bio = None v.bio = None
v.bio_html = None v.bio_html = None
g.db.add(v) g.db.add(v)
return render_template("settings_personal.html", v=v, msg="Your bio has been updated.") return render_template("settings/personal.html", v=v, msg="Your bio has been updated.")
elif not updated and request.values.get("sig") == "": elif not updated and request.values.get("sig") == "":
v.sig = None v.sig = None
v.sig_html = None v.sig_html = None
g.db.add(v) g.db.add(v)
return render_template("settings_personal.html", v=v, msg="Your sig has been updated.") return render_template("settings/personal.html", v=v, msg="Your sig has been updated.")
elif not updated and request.values.get("friends") == "": elif not updated and request.values.get("friends") == "":
v.friends = None v.friends = None
v.friends_html = None v.friends_html = None
g.db.add(v) g.db.add(v)
return render_template("settings_personal.html", v=v, msg="Your friends list has been updated.") return render_template("settings/personal.html", v=v, msg="Your friends list has been updated.")
elif not updated and request.values.get("enemies") == "": elif not updated and request.values.get("enemies") == "":
v.enemies = None v.enemies = None
v.enemies_html = None v.enemies_html = None
g.db.add(v) g.db.add(v)
return render_template("settings_personal.html", v=v, msg="Your enemies list has been updated.") return render_template("settings/personal.html", v=v, msg="Your enemies list has been updated.")
elif not updated and v.patron and request.values.get("sig"): elif not updated and v.patron and request.values.get("sig"):
sig = request.values.get("sig")[:200].replace('\n','').replace('\r','') sig = request.values.get("sig")[:200].replace('\n','').replace('\r','')
sig_html = sanitize(sig) sig_html = sanitize(sig)
if len(sig_html) > 1000: if len(sig_html) > 1000:
return render_template("settings_personal.html", return render_template("settings/personal.html",
v=v, v=v,
error="Your sig is too long") error="Your sig is too long")
v.sig = sig[:200] v.sig = sig[:200]
v.sig_html=sig_html v.sig_html=sig_html
g.db.add(v) g.db.add(v)
return render_template("settings_personal.html", return render_template("settings/personal.html",
v=v, v=v,
msg="Your sig has been updated.") msg="Your sig has been updated.")
@ -175,7 +175,7 @@ def settings_personal_post(v):
friends_html = sanitize(friends) friends_html = sanitize(friends)
if len(friends_html) > 2000: if len(friends_html) > 2000:
return render_template("settings_personal.html", return render_template("settings/personal.html",
v=v, v=v,
error="Your friends list is too long") error="Your friends list is too long")
@ -189,7 +189,7 @@ def settings_personal_post(v):
v.friends = friends[:500] v.friends = friends[:500]
v.friends_html=friends_html v.friends_html=friends_html
g.db.add(v) g.db.add(v)
return render_template("settings_personal.html", return render_template("settings/personal.html",
v=v, v=v,
msg="Your friends list has been updated.") msg="Your friends list has been updated.")
@ -200,7 +200,7 @@ def settings_personal_post(v):
enemies_html = sanitize(enemies) enemies_html = sanitize(enemies)
if len(enemies_html) > 2000: if len(enemies_html) > 2000:
return render_template("settings_personal.html", return render_template("settings/personal.html",
v=v, v=v,
error="Your enemies list is too long") error="Your enemies list is too long")
@ -213,7 +213,7 @@ def settings_personal_post(v):
v.enemies = enemies[:500] v.enemies = enemies[:500]
v.enemies_html=enemies_html v.enemies_html=enemies_html
g.db.add(v) g.db.add(v)
return render_template("settings_personal.html", return render_template("settings/personal.html",
v=v, v=v,
msg="Your enemies list has been updated.") msg="Your enemies list has been updated.")
@ -226,7 +226,7 @@ def settings_personal_post(v):
bio_html = sanitize(bio) bio_html = sanitize(bio)
if len(bio_html) > 10000: if len(bio_html) > 10000:
return render_template("settings_personal.html", return render_template("settings/personal.html",
v=v, v=v,
error="Your bio is too long") error="Your bio is too long")
@ -235,7 +235,7 @@ def settings_personal_post(v):
v.bio = bio[:1500] v.bio = bio[:1500]
v.bio_html=bio_html v.bio_html=bio_html
g.db.add(v) g.db.add(v)
return render_template("settings_personal.html", return render_template("settings/personal.html",
v=v, v=v,
msg="Your bio has been updated.") msg="Your bio has been updated.")
@ -298,11 +298,11 @@ def filters(v):
filters=request.values.get("filters")[:1000].strip() filters=request.values.get("filters")[:1000].strip()
if filters == v.custom_filter_list: if filters == v.custom_filter_list:
return render_template("settings_advanced.html", v=v, error="You didn't change anything") return render_template("settings/advanced.html", v=v, error="You didn't change anything")
v.custom_filter_list=filters v.custom_filter_list=filters
g.db.add(v) g.db.add(v)
return render_template("settings_advanced.html", v=v, msg="Your custom filters have been updated.") return render_template("settings/advanced.html", v=v, msg="Your custom filters have been updated.")
def set_color(v:User, attr:str, color:Optional[str]): def set_color(v:User, attr:str, color:Optional[str]):
@ -311,7 +311,7 @@ def set_color(v:User, attr:str, color:Optional[str]):
if color: if color:
if color.startswith('#'): color = color[1:] if color.startswith('#'): color = color[1:]
if not color_regex.fullmatch(color): if not color_regex.fullmatch(color):
return render_template("settings_personal.html", v=v, error="Invalid color hex code") return render_template("settings/personal.html", v=v, error="Invalid color hex code")
if color and current != color: if color and current != color:
setattr(v, attr, color) setattr(v, attr, color)
g.db.add(v) g.db.add(v)
@ -390,27 +390,27 @@ def verifiedcolor(v):
def settings_security_post(v): def settings_security_post(v):
if request.values.get("new_password"): if request.values.get("new_password"):
if request.values.get("new_password") != request.values.get("cnf_password"): if request.values.get("new_password") != request.values.get("cnf_password"):
return render_template("settings_security.html", v=v, error="Passwords do not match.") return render_template("settings/security.html", v=v, error="Passwords do not match.")
if not valid_password_regex.fullmatch(request.values.get("new_password")): if not valid_password_regex.fullmatch(request.values.get("new_password")):
return render_template("settings_security.html", v=v, error="Password must be between 8 and 100 characters.") return render_template("settings/security.html", v=v, error="Password must be between 8 and 100 characters.")
if not v.verifyPass(request.values.get("old_password")): if not v.verifyPass(request.values.get("old_password")):
return render_template("settings_security.html", v=v, error="Incorrect password") return render_template("settings/security.html", v=v, error="Incorrect password")
v.passhash = hash_password(request.values.get("new_password")) v.passhash = hash_password(request.values.get("new_password"))
g.db.add(v) g.db.add(v)
return render_template("settings_security.html", v=v, msg="Your password has been changed.") return render_template("settings/security.html", v=v, msg="Your password has been changed.")
if request.values.get("new_email"): if request.values.get("new_email"):
if not v.verifyPass(request.values.get('password')): if not v.verifyPass(request.values.get('password')):
return render_template("settings_security.html", v=v, error="Invalid password.") return render_template("settings/security.html", v=v, error="Invalid password.")
new_email = request.values.get("new_email","").strip().lower() new_email = request.values.get("new_email","").strip().lower()
if new_email == v.email: if new_email == v.email:
return render_template("settings_security.html", v=v, error="This email is already yours!") return render_template("settings/security.html", v=v, error="This email is already yours!")
url = f"{SITE_FULL}/activate" url = f"{SITE_FULL}/activate"
@ -432,29 +432,29 @@ def settings_security_post(v):
if request.values.get("2fa_token"): if request.values.get("2fa_token"):
if not v.verifyPass(request.values.get('password')): if not v.verifyPass(request.values.get('password')):
return render_template("settings_security.html", v=v, error="Invalid password or token.") return render_template("settings/security.html", v=v, error="Invalid password or token.")
secret = request.values.get("2fa_secret") secret = request.values.get("2fa_secret")
x = pyotp.TOTP(secret) x = pyotp.TOTP(secret)
if not x.verify(request.values.get("2fa_token"), valid_window=1): if not x.verify(request.values.get("2fa_token"), valid_window=1):
return render_template("settings_security.html", v=v, error="Invalid password or token.") return render_template("settings/security.html", v=v, error="Invalid password or token.")
v.mfa_secret = secret v.mfa_secret = secret
g.db.add(v) g.db.add(v)
return render_template("settings_security.html", v=v, msg="Two-factor authentication enabled.") return render_template("settings/security.html", v=v, msg="Two-factor authentication enabled.")
if request.values.get("2fa_remove"): if request.values.get("2fa_remove"):
if not v.verifyPass(request.values.get('password')): if not v.verifyPass(request.values.get('password')):
return render_template("settings_security.html", v=v, error="Invalid password or token.") return render_template("settings/security.html", v=v, error="Invalid password or token.")
token = request.values.get("2fa_remove") token = request.values.get("2fa_remove")
if not v.validate_2fa(token): if not v.validate_2fa(token):
return render_template("settings_security.html", v=v, error="Invalid password or token.") return render_template("settings/security.html", v=v, error="Invalid password or token.")
v.mfa_secret = None v.mfa_secret = None
g.db.add(v) g.db.add(v)
return render_template("settings_security.html", v=v, msg="Two-factor authentication disabled.") return render_template("settings/security.html", v=v, msg="Two-factor authentication disabled.")
@app.post("/settings/log_out_all_others") @app.post("/settings/log_out_all_others")
@limiter.limit("1/second;30/minute;200/hour;1000/day") @limiter.limit("1/second;30/minute;200/hour;1000/day")
@ -463,12 +463,12 @@ def settings_security_post(v):
def settings_log_out_others(v): def settings_log_out_others(v):
submitted_password = request.values.get("password", "").strip() submitted_password = request.values.get("password", "").strip()
if not v.verifyPass(submitted_password): if not v.verifyPass(submitted_password):
return render_template("settings_security.html", v=v, error="Incorrect Password"), 401 return render_template("settings/security.html", v=v, error="Incorrect Password"), 401
v.login_nonce += 1 v.login_nonce += 1
session["login_nonce"] = v.login_nonce session["login_nonce"] = v.login_nonce
g.db.add(v) g.db.add(v)
return render_template("settings_security.html", v=v, msg="All other devices have been logged out") return render_template("settings/security.html", v=v, msg="All other devices have been logged out")
@app.post("/settings/images/profile") @app.post("/settings/images/profile")
@ -503,7 +503,7 @@ def settings_images_profile(v):
g.db.add(v) g.db.add(v)
return render_template("settings_personal.html", v=v, msg="Profile picture successfully updated.") return render_template("settings/personal.html", v=v, msg="Profile picture successfully updated.")
@app.post("/settings/images/banner") @app.post("/settings/images/banner")
@ -527,12 +527,12 @@ def settings_images_banner(v):
v.bannerurl = bannerurl v.bannerurl = bannerurl
g.db.add(v) g.db.add(v)
return render_template("settings_personal.html", v=v, msg="Banner successfully updated.") return render_template("settings/personal.html", v=v, msg="Banner successfully updated.")
@app.get("/settings/css") @app.get("/settings/css")
@auth_required @auth_required
def settings_css_get(v): def settings_css_get(v):
return render_template("settings_css.html", v=v) return render_template("settings/css.html", v=v)
@app.post("/settings/css") @app.post("/settings/css")
@limiter.limit("1/second;30/minute;200/hour;1000/day") @limiter.limit("1/second;30/minute;200/hour;1000/day")
@ -546,7 +546,7 @@ def settings_css(v):
v.css = css v.css = css
g.db.add(v) g.db.add(v)
return render_template("settings_css.html", v=v) return render_template("settings/css.html", v=v)
@app.post("/settings/profilecss") @app.post("/settings/profilecss")
@limiter.limit("1/second;30/minute;200/hour;1000/day") @limiter.limit("1/second;30/minute;200/hour;1000/day")
@ -556,7 +556,7 @@ def settings_profilecss(v):
profilecss = request.values.get("profilecss", v.profilecss).strip().replace('\\', '').strip()[:4000] profilecss = request.values.get("profilecss", v.profilecss).strip().replace('\\', '').strip()[:4000]
valid, error = validate_css(profilecss) valid, error = validate_css(profilecss)
if not valid: if not valid:
return render_template("settings_css.html", error=error, v=v) return render_template("settings/css.html", error=error, v=v)
v.profilecss = profilecss v.profilecss = profilecss
g.db.add(v) g.db.add(v)
return redirect('/settings/css') return redirect('/settings/css')
@ -564,7 +564,7 @@ def settings_profilecss(v):
@app.get("/settings/security") @app.get("/settings/security")
@auth_required @auth_required
def settings_security(v): def settings_security(v):
return render_template("settings_security.html", return render_template("settings/security.html",
v=v, v=v,
mfa_secret=pyotp.random_base32() if not v.mfa_secret else None, mfa_secret=pyotp.random_base32() if not v.mfa_secret else None,
now=int(time.time()) now=int(time.time())
@ -614,12 +614,12 @@ def settings_unblock_user(v):
@app.get("/settings/apps") @app.get("/settings/apps")
@auth_required @auth_required
def settings_apps(v): def settings_apps(v):
return render_template("settings_apps.html", v=v) return render_template("settings/apps.html", v=v)
@app.get("/settings/advanced") @app.get("/settings/advanced")
@auth_required @auth_required
def settings_advanced_get(v): def settings_advanced_get(v):
return render_template("settings_advanced.html", v=v) return render_template("settings/advanced.html", v=v)
@app.post("/settings/name_change") @app.post("/settings/name_change")
@limiter.limit("1/second;30/minute;200/hour;1000/day") @limiter.limit("1/second;30/minute;200/hour;1000/day")
@ -629,12 +629,12 @@ def settings_name_change(v):
new_name=request.values.get("name").strip() new_name=request.values.get("name").strip()
if new_name==v.username: if new_name==v.username:
return render_template("settings_personal.html", return render_template("settings/personal.html",
v=v, v=v,
error="You didn't change anything") error="You didn't change anything")
if not valid_username_regex.fullmatch(new_name): if not valid_username_regex.fullmatch(new_name):
return render_template("settings_personal.html", return render_template("settings/personal.html",
v=v, v=v,
error="This isn't a valid username.") error="This isn't a valid username.")
@ -648,7 +648,7 @@ def settings_name_change(v):
).one_or_none() ).one_or_none()
if x and x.id != v.id: if x and x.id != v.id:
return render_template("settings_personal.html", return render_template("settings/personal.html",
v=v, v=v,
error=f"Username `{new_name}` is already in use.") error=f"Username `{new_name}` is already in use.")
@ -667,7 +667,7 @@ def settings_name_change(v):
def settings_song_change_mp3(v): def settings_song_change_mp3(v):
file = request.files['file'] file = request.files['file']
if file.content_type != 'audio/mpeg': if file.content_type != 'audio/mpeg':
return render_template("settings_personal.html", v=v, error="Not a valid MP3 file") return render_template("settings/personal.html", v=v, error="Not a valid MP3 file")
song = str(time.time()).replace('.','') song = str(time.time()).replace('.','')
@ -677,7 +677,7 @@ def settings_song_change_mp3(v):
size = os.stat(name).st_size size = os.stat(name).st_size
if size > 8 * 1024 * 1024: if size > 8 * 1024 * 1024:
os.remove(name) os.remove(name)
return render_template("settings_personal.html", v=v, error="MP3 file must be smaller than 8MB") return render_template("settings/personal.html", v=v, error="MP3 file must be smaller than 8MB")
if path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).filter_by(song=v.song).count() == 1: if path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).filter_by(song=v.song).count() == 1:
os.remove(f"/songs/{v.song}.mp3") os.remove(f"/songs/{v.song}.mp3")
@ -708,7 +708,7 @@ def settings_song_change(v):
elif song.startswith("https://youtu.be/"): elif song.startswith("https://youtu.be/"):
id = song.split("https://youtu.be/")[1] id = song.split("https://youtu.be/")[1]
else: else:
return render_template("settings_personal.html", v=v, error="Not a youtube link.") return render_template("settings/personal.html", v=v, error="Not a youtube link.")
if "?" in id: id = id.split("?")[0] if "?" in id: id = id.split("?")[0]
if "&" in id: id = id.split("&")[0] if "&" in id: id = id.split("&")[0]
@ -722,15 +722,15 @@ def settings_song_change(v):
req = requests.get(f"https://www.googleapis.com/youtube/v3/videos?id={id}&key={YOUTUBE_KEY}&part=contentDetails", timeout=5).json() req = requests.get(f"https://www.googleapis.com/youtube/v3/videos?id={id}&key={YOUTUBE_KEY}&part=contentDetails", timeout=5).json()
duration = req['items'][0]['contentDetails']['duration'] duration = req['items'][0]['contentDetails']['duration']
if duration == 'P0D': if duration == 'P0D':
return render_template("settings_personal.html", v=v, error="Can't use a live youtube video!") return render_template("settings/personal.html", v=v, error="Can't use a live youtube video!")
if "H" in duration: if "H" in duration:
return render_template("settings_personal.html", v=v, error="Duration of the video must not exceed 15 minutes.") return render_template("settings/personal.html", v=v, error="Duration of the video must not exceed 15 minutes.")
if "M" in duration: if "M" in duration:
duration = int(duration.split("PT")[1].split("M")[0]) duration = int(duration.split("PT")[1].split("M")[0])
if duration > 15: if duration > 15:
return render_template("settings_personal.html", v=v, error="Duration of the video must not exceed 15 minutes.") return render_template("settings/personal.html", v=v, error="Duration of the video must not exceed 15 minutes.")
if v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).filter_by(song=v.song).count() == 1: if v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).filter_by(song=v.song).count() == 1:
@ -750,7 +750,7 @@ def settings_song_change(v):
try: ydl.download([f"https://youtube.com/watch?v={id}"]) try: ydl.download([f"https://youtube.com/watch?v={id}"])
except Exception as e: except Exception as e:
print(e, flush=True) print(e, flush=True)
return render_template("settings_personal.html", return render_template("settings/personal.html",
v=v, v=v,
error="Age-restricted videos aren't allowed.") error="Age-restricted videos aren't allowed.")
@ -772,13 +772,13 @@ def settings_title_change(v):
customtitleplain = sanitize_settings_text(request.values.get("title"), 100) customtitleplain = sanitize_settings_text(request.values.get("title"), 100)
if customtitleplain == v.customtitleplain: if customtitleplain == v.customtitleplain:
return render_template("settings_personal.html", v=v, error="You didn't change anything") return render_template("settings/personal.html", v=v, error="You didn't change anything")
customtitle = filter_emojis_only(customtitleplain) customtitle = filter_emojis_only(customtitleplain)
customtitle = censor_slurs(customtitle, None) customtitle = censor_slurs(customtitle, None)
if len(customtitle) > 1000: if len(customtitle) > 1000:
return render_template("settings_personal.html", v=v, error="Flair too long!") return render_template("settings/personal.html", v=v, error="Flair too long!")
v.customtitleplain = customtitleplain v.customtitleplain = customtitleplain
v.customtitle = customtitle v.customtitle = customtitle
@ -796,13 +796,13 @@ def settings_pronouns_change(v):
pronouns = sanitize_settings_text(request.values.get("pronouns")) pronouns = sanitize_settings_text(request.values.get("pronouns"))
if len(pronouns) > 11: if len(pronouns) > 11:
return render_template("settings_personal.html", v=v, error="Your pronouns exceed the character limit (11 characters)") return render_template("settings/personal.html", v=v, error="Your pronouns exceed the character limit (11 characters)")
if pronouns == v.pronouns: if pronouns == v.pronouns:
return render_template("settings_personal.html", v=v, error="You didn't change anything.") return render_template("settings/personal.html", v=v, error="You didn't change anything.")
if not pronouns_regex.fullmatch(pronouns): if not pronouns_regex.fullmatch(pronouns):
return render_template("settings_personal.html", v=v, error="The pronouns you entered don't match the required format.") return render_template("settings/personal.html", v=v, error="The pronouns you entered don't match the required format.")
bare_pronouns = pronouns.lower().replace('/', '') bare_pronouns = pronouns.lower().replace('/', '')
if 'nig' in bare_pronouns: pronouns = 'BI/POC' if 'nig' in bare_pronouns: pronouns = 'BI/POC'
@ -822,7 +822,7 @@ def settings_checkmark_text(v):
if not v.verified: abort(403) if not v.verified: abort(403)
new_name = sanitize_settings_text(request.values.get("checkmark-text"), 100) new_name = sanitize_settings_text(request.values.get("checkmark-text"), 100)
if not new_name: abort(400) if not new_name: abort(400)
if new_name == v.verified: return render_template("settings_personal.html", v=v, error="You didn't change anything") if new_name == v.verified: return render_template("settings/personal.html", v=v, error="You didn't change anything")
v.verified = new_name v.verified = new_name
g.db.add(v) g.db.add(v)
return redirect("/settings/personal") return redirect("/settings/personal")

View File

@ -55,25 +55,25 @@ def upvoters_downvoters(v, username, uid, cls, vote_cls, vote_dir, template, sta
@app.get("/@<username>/upvoters/<uid>/posts") @app.get("/@<username>/upvoters/<uid>/posts")
@auth_required @auth_required
def upvoters_posts(v, username, uid): def upvoters_posts(v, username, uid):
return upvoters_downvoters(v, username, uid, Submission, Vote, 1, "voted_posts.html", None) return upvoters_downvoters(v, username, uid, Submission, Vote, 1, "userpage/voted_posts.html", None)
@app.get("/@<username>/upvoters/<uid>/comments") @app.get("/@<username>/upvoters/<uid>/comments")
@auth_required @auth_required
def upvoters_comments(v, username, uid): def upvoters_comments(v, username, uid):
return upvoters_downvoters(v, username, uid, Comment, CommentVote, 1, "voted_comments.html", True) return upvoters_downvoters(v, username, uid, Comment, CommentVote, 1, "userpage/voted_comments.html", True)
@app.get("/@<username>/downvoters/<uid>/posts") @app.get("/@<username>/downvoters/<uid>/posts")
@auth_required @auth_required
def downvoters_posts(v, username, uid): def downvoters_posts(v, username, uid):
return upvoters_downvoters(v, username, uid, Submission, Vote, -1, "voted_posts.html", None) return upvoters_downvoters(v, username, uid, Submission, Vote, -1, "userpage/voted_posts.html", None)
@app.get("/@<username>/downvoters/<uid>/comments") @app.get("/@<username>/downvoters/<uid>/comments")
@auth_required @auth_required
def downvoters_comments(v, username, uid): def downvoters_comments(v, username, uid):
return upvoters_downvoters(v, username, uid, Comment, CommentVote, -1, "voted_comments.html", True) return upvoters_downvoters(v, username, uid, Comment, CommentVote, -1, "userpage/voted_comments.html", True)
def upvoting_downvoting(v, username, uid, cls, vote_cls, vote_dir, template, standalone): def upvoting_downvoting(v, username, uid, cls, vote_cls, vote_dir, template, standalone):
u = get_user(username, v=v, include_shadowbanned=False) u = get_user(username, v=v, include_shadowbanned=False)
@ -106,25 +106,25 @@ def upvoting_downvoting(v, username, uid, cls, vote_cls, vote_dir, template, sta
@app.get("/@<username>/upvoting/<uid>/posts") @app.get("/@<username>/upvoting/<uid>/posts")
@auth_required @auth_required
def upvoting_posts(v, username, uid): def upvoting_posts(v, username, uid):
return upvoting_downvoting(v, username, uid, Submission, Vote, 1, "voted_posts.html", None) return upvoting_downvoting(v, username, uid, Submission, Vote, 1, "userpage/voted_posts.html", None)
@app.get("/@<username>/upvoting/<uid>/comments") @app.get("/@<username>/upvoting/<uid>/comments")
@auth_required @auth_required
def upvoting_comments(v, username, uid): def upvoting_comments(v, username, uid):
return upvoting_downvoting(v, username, uid, Comment, CommentVote, 1, "voted_comments.html", True) return upvoting_downvoting(v, username, uid, Comment, CommentVote, 1, "userpage/voted_comments.html", True)
@app.get("/@<username>/downvoting/<uid>/posts") @app.get("/@<username>/downvoting/<uid>/posts")
@auth_required @auth_required
def downvoting_posts(v, username, uid): def downvoting_posts(v, username, uid):
return upvoting_downvoting(v, username, uid, Submission, Vote, -1, "voted_posts.html", None) return upvoting_downvoting(v, username, uid, Submission, Vote, -1, "userpage/voted_posts.html", None)
@app.get("/@<username>/downvoting/<uid>/comments") @app.get("/@<username>/downvoting/<uid>/comments")
@auth_required @auth_required
def downvoting_comments(v, username, uid): def downvoting_comments(v, username, uid):
return upvoting_downvoting(v, username, uid, Comment, CommentVote, -1, "voted_comments.html", True) return upvoting_downvoting(v, username, uid, Comment, CommentVote, -1, "userpage/voted_comments.html", True)
def user_voted(v, username, cls, vote_cls, vote_dir, template, standalone): def user_voted(v, username, cls, vote_cls, vote_dir, template, standalone):
u = get_user(username, v=v, include_shadowbanned=False) u = get_user(username, v=v, include_shadowbanned=False)
@ -158,13 +158,13 @@ def user_voted(v, username, cls, vote_cls, vote_dir, template, standalone):
@app.get("/@<username>/upvoted/posts") @app.get("/@<username>/upvoted/posts")
@auth_required @auth_required
def user_upvoted_posts(v, username): def user_upvoted_posts(v, username):
return user_voted(v, username, Submission, Vote, 1, "voted_posts.html", None) return user_voted(v, username, Submission, Vote, 1, "userpage/voted_posts.html", None)
@app.get("/@<username>/upvoted/comments") @app.get("/@<username>/upvoted/comments")
@auth_required @auth_required
def user_upvoted_comments(v, username): def user_upvoted_comments(v, username):
return user_voted(v, username, Comment, CommentVote, 1, "voted_comments.html", True) return user_voted(v, username, Comment, CommentVote, 1, "userpage/voted_comments.html", True)
@app.get("/grassed") @app.get("/grassed")
@ -228,7 +228,7 @@ def all_upvoters_downvoters(v, username, vote_dir, is_who_simps_hates):
name2 = f'Who @{username} {simps_haters}' if is_who_simps_hates else f'@{username} biggest {simps_haters}' name2 = f'Who @{username} {simps_haters}' if is_who_simps_hates else f'@{username} biggest {simps_haters}'
return render_template("voters.html", v=v, users=users[:PAGE_SIZE], pos=pos, name=vote_name, name2=name2, total=total) return render_template("userpage/voters.html", v=v, users=users[:PAGE_SIZE], pos=pos, name=vote_name, name2=name2, total=total)
@app.get("/@<username>/upvoters") @app.get("/@<username>/upvoters")
@auth_required @auth_required
@ -631,7 +631,7 @@ def followers(username, v):
users = g.db.query(Follow, User).join(Follow, Follow.target_id == u.id) \ users = g.db.query(Follow, User).join(Follow, Follow.target_id == u.id) \
.filter(Follow.user_id == User.id) \ .filter(Follow.user_id == User.id) \
.order_by(Follow.created_utc).all() .order_by(Follow.created_utc).all()
return render_template("followers.html", v=v, u=u, users=users) return render_template("userpage/followers.html", v=v, u=u, users=users)
@app.get("/@<username>/blockers") @app.get("/@<username>/blockers")
@auth_required @auth_required
@ -641,7 +641,7 @@ def blockers(username, v):
users = g.db.query(UserBlock, User).join(UserBlock, UserBlock.target_id == u.id) \ users = g.db.query(UserBlock, User).join(UserBlock, UserBlock.target_id == u.id) \
.filter(UserBlock.user_id == User.id) \ .filter(UserBlock.user_id == User.id) \
.order_by(UserBlock.created_utc).all() .order_by(UserBlock.created_utc).all()
return render_template("blockers.html", v=v, u=u, users=users) return render_template("userpage/blockers.html", v=v, u=u, users=users)
@app.get("/@<username>/following") @app.get("/@<username>/following")
@auth_required @auth_required
@ -653,7 +653,7 @@ def following(username, v):
users = g.db.query(User).join(Follow, Follow.user_id == u.id) \ users = g.db.query(User).join(Follow, Follow.user_id == u.id) \
.filter(Follow.target_id == User.id) \ .filter(Follow.target_id == User.id) \
.order_by(Follow.created_utc).all() .order_by(Follow.created_utc).all()
return render_template("following.html", v=v, u=u, users=users) return render_template("userpage/following.html", v=v, u=u, users=users)
@app.get("/views") @app.get("/views")
@auth_required @auth_required
@ -661,7 +661,7 @@ def visitors(v):
if not v.viewers_recorded: if not v.viewers_recorded:
return render_template("errors/patron.html", v=v) return render_template("errors/patron.html", v=v)
viewers=sorted(v.viewers, key = lambda x: x.last_view_utc, reverse=True) viewers=sorted(v.viewers, key = lambda x: x.last_view_utc, reverse=True)
return render_template("viewers.html", v=v, viewers=viewers) return render_template("userpage/viewers.html", v=v, viewers=viewers)
@app.get("/@<username>") @app.get("/@<username>")
@ -687,13 +687,13 @@ def u_username(username, v=None):
if not u.is_visible_to(v): if not u.is_visible_to(v):
if g.is_api_or_xhr or request.path.endswith(".json"): if g.is_api_or_xhr or request.path.endswith(".json"):
abort(403, "This userpage is private") abort(403, "This userpage is private")
return render_template("userpage_private.html", u=u, v=v, is_following=is_following), 403 return render_template("userpage/private.html", u=u, v=v, is_following=is_following), 403
if v and hasattr(u, 'is_blocking') and u.is_blocking: if v and hasattr(u, 'is_blocking') and u.is_blocking:
if g.is_api_or_xhr or request.path.endswith(".json"): if g.is_api_or_xhr or request.path.endswith(".json"):
abort(403, f"You are blocking @{u.username}.") abort(403, f"You are blocking @{u.username}.")
return render_template("userpage_blocking.html", u=u, v=v), 403 return render_template("userpage/blocking.html", u=u, v=v), 403
sort = request.values.get("sort", "new") sort = request.values.get("sort", "new")
@ -756,12 +756,12 @@ def u_username_comments(username, v=None):
if not u.is_visible_to(v): if not u.is_visible_to(v):
if g.is_api_or_xhr or request.path.endswith(".json"): if g.is_api_or_xhr or request.path.endswith(".json"):
abort(403, "This userpage is private") abort(403, "This userpage is private")
return render_template("userpage_private.html", u=u, v=v, is_following=is_following), 403 return render_template("userpage/private.html", u=u, v=v, is_following=is_following), 403
if v and hasattr(u, 'is_blocking') and u.is_blocking: if v and hasattr(u, 'is_blocking') and u.is_blocking:
if g.is_api_or_xhr or request.path.endswith(".json"): if g.is_api_or_xhr or request.path.endswith(".json"):
abort(403, f"You are blocking @{u.username}.") abort(403, f"You are blocking @{u.username}.")
return render_template("userpage_blocking.html", u=u, v=v), 403 return render_template("userpage/blocking.html", u=u, v=v), 403
try: page = max(int(request.values.get("page", "1")), 1) try: page = max(int(request.values.get("page", "1")), 1)
except: page = 1 except: page = 1
@ -801,7 +801,7 @@ def u_username_comments(username, v=None):
if (v and v.client) or request.path.endswith(".json"): if (v and v.client) or request.path.endswith(".json"):
return {"data": [c.json for c in listing]} return {"data": [c.json for c in listing]}
return render_template("userpage_comments.html", u=u, v=v, listing=listing, page=page, sort=sort, t=t,next_exists=next_exists, is_following=is_following, standalone=True) return render_template("userpage/comments.html", u=u, v=v, listing=listing, page=page, sort=sort, t=t,next_exists=next_exists, is_following=is_following, standalone=True)
@app.get("/@<username>/info") @app.get("/@<username>/info")
@ -969,7 +969,7 @@ def saved_comments(v, username):
try: page = max(1, int(request.values.get("page", 1))) try: page = max(1, int(request.values.get("page", 1)))
except: abort(400, "Invalid page input!") except: abort(400, "Invalid page input!")
return get_saves_and_subscribes(v, "userpage_comments.html", CommentSaveRelationship, page, True) return get_saves_and_subscribes(v, "userpage/comments.html", CommentSaveRelationship, page, True)
@app.get("/@<username>/subscribed/posts") @app.get("/@<username>/subscribed/posts")
@auth_required @auth_required

View File

@ -1,7 +1,7 @@
{% extends "settings.html" %} {% extends "settings.html" %}
{% block pagetitle %}Advanced Settings - {{SITE_NAME}}{% endblock %} {% block pagetitle %}Advanced Settings - {{SITE_NAME}}{% endblock %}
{% block content %} {% block content %}
{% import 'settings_common.html' as common with context %} {% import 'settings/common.html' as common with context %}
<div class="row settings-page" id="settings-page-advanced"> <div class="row settings-page" id="settings-page-advanced">
<div class="col col-lg-8"> <div class="col col-lg-8">
<div class="settings"> <div class="settings">

View File

@ -1,6 +1,6 @@
{% extends "settings.html" %} {% extends "settings.html" %}
{% block pagetitle %}Personal Settings - {{SITE_NAME}}{% endblock %} {% block pagetitle %}Personal Settings - {{SITE_NAME}}{% endblock %}
{% import 'settings_common.html' as common with context %} {% import 'settings/common.html' as common with context %}
{% block content %} {% block content %}
<style> <style>
.bg-image { .bg-image {

View File

@ -29,7 +29,7 @@
<meta name="twitter:url" content="{{u.url}}"> <meta name="twitter:url" content="{{u.url}}">
{% endblock %} {% endblock %}
{% import 'userpage_admintools.html' as userpage_admintools with context %} {% import 'userpage/admintools.html' as userpage_admintools with context %}
{% set hats_total = u.hats_owned_proportion_display[1] if u else 0 %} {% set hats_total = u.hats_owned_proportion_display[1] if u else 0 %}
{% set hats_owned_percent = u.hats_owned_proportion_display[0] if u else '' %} {% set hats_owned_percent = u.hats_owned_proportion_display[0] if u else '' %}