From b2de11cb1ab0d496f9b823659c61c6397e144dee Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Wed, 13 Jul 2022 19:31:35 +0200 Subject: [PATCH] add "pins" toggle to the frontpage --- files/helpers/const.py | 2 -- files/routes/front.py | 13 ++++++++----- files/routes/users.py | 9 +++++++++ files/templates/home.html | 20 +++++++++++++------- files/templates/util/assetcache.html | 2 +- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/files/helpers/const.py b/files/helpers/const.py index 924177c4d7..aa94a047d3 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -177,7 +177,6 @@ AEVANN_ID = 5 SNAKES_ID = 0 HOMO_ID = 0 SOREN_ID = 0 -Q_ID = 0 LAWLZ_ID = 0 LLM_ID = 0 DAD_ID = 0 @@ -237,7 +236,6 @@ if SITE in {'rdrama.net', 'devrama.xyz', 'deuxrama.net'}: SNAKES_ID = 10288 HOMO_ID = 147 SOREN_ID = 2546 - Q_ID = 1480 LAWLZ_ID = 3833 LLM_ID = 253 DAD_ID = 2513 diff --git a/files/routes/front.py b/files/routes/front.py index bacc6981d5..34f2f506de 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -51,6 +51,8 @@ def front_all(v, sub=None, subdomain=None): try: lt=int(request.values.get("before", 0)) except: lt=0 + pins = session.get("pins", True) + ids, next_exists = frontlist(sort=sort, page=page, t=t, @@ -60,7 +62,8 @@ def front_all(v, sub=None, subdomain=None): gt=gt, lt=lt, sub=sub, - site=SITE + site=SITE, + pins=pins ) posts = get_posts(ids, v=v) @@ -70,12 +73,12 @@ def front_all(v, sub=None, subdomain=None): award_timers(v) if request.headers.get("Authorization"): return {"data": [x.json for x in posts], "next_exists": next_exists} - return render_template("home.html", v=v, listing=posts, next_exists=next_exists, sort=sort, t=t, page=page, ccmode=ccmode, sub=sub, home=True) + return render_template("home.html", v=v, listing=posts, next_exists=next_exists, sort=sort, t=t, page=page, ccmode=ccmode, sub=sub, home=True, pins=pins) @cache.memoize(timeout=86400) -def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, ccmode="false", filter_words='', gt=0, lt=0, sub=None, site=None): +def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, ccmode="false", filter_words='', gt=0, lt=0, sub=None, site=None, pins=True): posts = g.db.query(Submission) @@ -97,7 +100,7 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, ccmode="false" posts = posts.filter_by(is_banned=False, private=False, deleted_utc = 0) - if (sort == "hot" or (v and v.id == Q_ID)) and ccmode == "false" and not gt and not lt: + if pins and ccmode == "false" and not gt and not lt: posts = posts.filter_by(stickied=None, hole_pinned=None) if v: @@ -137,7 +140,7 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, ccmode="false" posts = posts[:size] - if (sort == "hot" or (v and v.id == Q_ID)) and page == 1 and ccmode == "false" and not gt and not lt: + if pins and page == 1 and ccmode == "false" and not gt and not lt: if sub: pins = g.db.query(Submission).filter(Submission.sub == sub.name, Submission.hole_pinned != None) else: diff --git a/files/routes/users.py b/files/routes/users.py index df3c82c833..5d0d9ce49a 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -1263,3 +1263,12 @@ def fp(v, fp): print(v.username + ' + ' + u.username, flush=True) g.db.add(v) return '', 204 + +@app.get("/toggle_pins") +def toggle_pins(): + pins = session.get("pins", True) + session['pins'] = not pins + if is_site_url(request.referrer): + return redirect(request.referrer) + + return redirect('/') \ No newline at end of file diff --git a/files/templates/home.html b/files/templates/home.html index 1b3521301c..0030d4f426 100644 --- a/files/templates/home.html +++ b/files/templates/home.html @@ -38,18 +38,24 @@ Catalog {% endif %} + {% if pins %} + Pins + {% else %} + Pins + {% endif %} + {% if v and SITE_NAME == 'rDrama' %} {% if v.paid_dues %} - {% if ccmode=="true"%} - CC + {% if ccmode=="true" %} + CC {% else %} - CC + CC {% endif %} {% endif %} {% endif %}