From f56be06eb8412bbc8664e3c2a11a36b30dd05fb7 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 2 Jul 2022 01:11:48 +0200 Subject: [PATCH] add hole pinning --- files/classes/submission.py | 1 + files/helpers/get.py | 6 +++++ files/routes/front.py | 21 +++++++++--------- files/routes/subs.py | 28 ++++++++++++++++++++++++ files/templates/post_actions.html | 5 +++++ files/templates/post_actions_mobile.html | 4 ++++ files/templates/submission.html | 4 ++++ files/templates/submission_listing.html | 4 ++++ 8 files changed, 63 insertions(+), 10 deletions(-) diff --git a/files/classes/submission.py b/files/classes/submission.py index 77e0b969d..19ed2827d 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -48,6 +48,7 @@ class Submission(Base): distinguish_level = Column(Integer, default=0) stickied = Column(String) stickied_utc = Column(Integer) + hole_pinned = Column(String) sub = Column(String, ForeignKey("subs.name")) is_pinned = Column(Boolean, default=False) private = Column(Boolean, default=False) diff --git a/files/helpers/get.py b/files/helpers/get.py index d294d35fb..9daf3aa0f 100644 --- a/files/helpers/get.py +++ b/files/helpers/get.py @@ -115,6 +115,9 @@ def get_account(id, v=None): def get_post(i, v=None, graceful=False, rendered=False): + try: i = int(i) + except: abort(404) + if not i: if graceful: return None else: abort(404) @@ -207,6 +210,9 @@ def get_posts(pids, v=None): def get_comment(i, v=None, graceful=False): + try: i = int(i) + except: abort(404) + if not i: if graceful: return None else: abort(404) diff --git a/files/routes/front.py b/files/routes/front.py index 0fdacf64c..779e71025 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -276,7 +276,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: - posts = posts.filter_by(stickied=None) + posts = posts.filter_by(stickied=None, hole_pinned=None) if v: posts = posts.filter(Submission.author_id.notin_(v.userblocks)) @@ -313,20 +313,21 @@ 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: - pins = g.db.query(Submission).filter(Submission.stickied != None, Submission.is_banned == False) - if sub: pins = pins.filter_by(sub=sub.name) + if sub: + pins = g.db.query(Submission).filter(Submission.sub == sub.name, Submission.hole_pinned != None) elif v: + pins = g.db.query(Submission).filter(Submission.stickied != None, Submission.is_banned == False) pins = pins.filter(or_(Submission.sub == None, Submission.sub.notin_(v.all_blocks))) pins = pins.filter(Submission.author_id.notin_(v.userblocks)) - pins = pins.order_by(Submission.created_utc.desc()).all() + for pin in pins: + if pin.stickied_utc and int(time.time()) > pin.stickied_utc: + pin.stickied = None + pin.stickied_utc = None + g.db.add(pin) + pins.remove(pin) - for pin in pins: - if pin.stickied_utc and int(time.time()) > pin.stickied_utc: - pin.stickied = None - pin.stickied_utc = None - g.db.add(pin) - pins.remove(pin) + pins = pins.order_by(Submission.created_utc.desc()).all() posts = pins + posts diff --git a/files/routes/subs.py b/files/routes/subs.py index 008cfebd6..e06cab457 100644 --- a/files/routes/subs.py +++ b/files/routes/subs.py @@ -530,3 +530,31 @@ def sub_inactive_purge_task(): g.db.delete(x) return True + +@app.post("/hole_pin/") +@auth_required +def hole_pin(v, pid): + p = get_post(pid) + + if not p.sub: abort(403) + + if not v.mods(p.sub): abort(403) + + p.hole_pinned = v.username + g.db.add(p) + + return {"message": f"Post pinned to /h/{p.sub}"} + +@app.post("/hole_unpin/") +@auth_required +def hole_unpin(v, pid): + p = get_post(pid) + + if not p.sub: abort(403) + + if not v.mods(p.sub): abort(403) + + p.hole_pinned = None + g.db.add(p) + + return {"message": f"Post unpinned from /h/{p.sub}"} diff --git a/files/templates/post_actions.html b/files/templates/post_actions.html index fd6a3328d..888770680 100644 --- a/files/templates/post_actions.html +++ b/files/templates/post_actions.html @@ -50,6 +50,11 @@ Unpin {% endif %} + {% if p.sub and v.mods(p.sub) %} + Pin to /h/{{p.sub}} + Unpin fron /h/{{p.sub}} + {% endif %} + {% if v.admin_level > 1 or v.id == p.author_id %} Mark club Unmark club diff --git a/files/templates/post_actions_mobile.html b/files/templates/post_actions_mobile.html index f01ee5a61..88ecff6fc 100644 --- a/files/templates/post_actions_mobile.html +++ b/files/templates/post_actions_mobile.html @@ -20,6 +20,10 @@ +{% if p.sub and v.mods(p.sub) %} + + +{% endif %} {% if v.id==p.author_id %} {% if request.path.startswith('/@') %} diff --git a/files/templates/submission.html b/files/templates/submission.html index ddc9b1e2b..6ed1b8f8b 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -730,6 +730,10 @@ {% endif %} + {% if p.hole_pinned %} + + {% endif %} + {% if p.is_pinned %}{% endif %} {% if p.distinguish_level %} {% endif %} {% if p.is_bot %} {% endif %} diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 4cff2dd11..04d8640fe 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -178,6 +178,10 @@ {% endif %} + {% if p.hole_pinned %} + + {% endif %} + {% if p.distinguish_level %}{% endif %} {% if p.is_pinned and request.path.startswith('/@') %}{% endif %} {% if p.over_18 %}+18{% endif %}