From cbf7405c97b4b258f4bbc705216ad9bc125442ac Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 21 Oct 2021 01:37:53 +0200 Subject: [PATCH] unpin award --- files/classes/award.py | 16 +++++++++++++ files/classes/user.py | 16 +++++++++++++ files/routes/admin.py | 17 +++++++++----- files/routes/awards.py | 40 ++++++++++++++++++++++++++++++++ files/routes/posts.py | 10 ++++---- files/routes/settings.py | 3 +++ files/templates/award_modal.html | 2 +- files/templates/submission.html | 4 ++-- 8 files changed, 94 insertions(+), 14 deletions(-) diff --git a/files/classes/award.py b/files/classes/award.py index 022687ebe..8e823e90a 100755 --- a/files/classes/award.py +++ b/files/classes/award.py @@ -64,6 +64,14 @@ if site_name == "Drama": "color": "text-warning", "price": 750 }, + "unpin": { + "kind": "unpin", + "title": "1-Hour Unpin", + "description": "Removes 1 hour from the pin duration of the post.", + "icon": "fas fa-thumbtack", + "color": "text-black", + "price": 1000 + }, } else: AWARDS = { @@ -99,6 +107,14 @@ else: "color": "text-warning", "price": 750 }, + "unpin": { + "kind": "unpin", + "title": "1-Hour Unpin", + "description": "Removes 1 hour from the pin duration of the post.", + "icon": "fas fa-thumbtack", + "color": "text-black", + "price": 1000 + }, } diff --git a/files/classes/user.py b/files/classes/user.py index 313e09965..b6400e8e3 100755 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -81,6 +81,14 @@ if site_name == "Drama": "color": "text-warning", "price": 750 }, + "unpin": { + "kind": "unpin", + "title": "1-Hour Unpin", + "description": "Removes 1 hour from the pin duration of the post.", + "icon": "fas fa-thumbtack", + "color": "text-black", + "price": 1000 + }, } else: AWARDS = { @@ -116,6 +124,14 @@ else: "color": "text-warning", "price": 750 }, + "unpin": { + "kind": "unpin", + "title": "1-Hour Unpin", + "description": "Removes 1 hour from the pin duration of the post.", + "icon": "fas fa-thumbtack", + "color": "text-black", + "price": 1000 + }, } class User(Base): diff --git a/files/routes/admin.py b/files/routes/admin.py index a279047a7..cad3fabad 100755 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -192,12 +192,14 @@ def monthly(v): grant_awards["fireflies"] = 10 grant_awards["train"] = 10 grant_awards["ban"] = 5 + grant_awards["pin"] = 1 elif u.patron == 5 or u.patron == 8: grant_awards["shit"] = 20 grant_awards["fireflies"] = 20 grant_awards["train"] = 20 grant_awards["ban"] = 10 - + grant_awards["pin"] = 2 + grant_awards["unpin"] = 1 for name in grant_awards: for count in range(grant_awards[name]): @@ -439,12 +441,15 @@ def badge_grant_post(v): grant_awards["fireflies"] = 10 grant_awards["train"] = 10 grant_awards["ban"] = 5 + grant_awards["pin"] = 1 elif badge_id == 25: - if user.discord_id: add_role(user, "5") - grant_awards["shit"] = 20 - grant_awards["fireflies"] = 20 - grant_awards["train"] = 20 - grant_awards["ban"] = 10 + if user.discord_id: add_role(user, "5") + grant_awards["shit"] = 20 + grant_awards["fireflies"] = 20 + grant_awards["train"] = 20 + grant_awards["ban"] = 10 + grant_awards["pin"] = 2 + grant_awards["unpin"] = 1 if len(grant_awards): diff --git a/files/routes/awards.py b/files/routes/awards.py index 25c037185..b4f3c70d0 100755 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -69,6 +69,14 @@ def shop(v): "color": "text-warning", "price": 750 }, + "unpin": { + "kind": "unpin", + "title": "1-Hour Unpin", + "description": "Removes 1 hour from the pin duration of the post.", + "icon": "fas fa-thumbtack", + "color": "text-black", + "price": 1000 + }, } else: AWARDS = { @@ -104,6 +112,14 @@ def shop(v): "color": "text-warning", "price": 750 }, + "unpin": { + "kind": "unpin", + "title": "1-Hour Unpin", + "description": "Removes 1 hour from the pin duration of the post.", + "icon": "fas fa-thumbtack", + "color": "text-black", + "price": 1000 + }, } query = g.db.query( @@ -194,6 +210,14 @@ def buy(v, award): "color": "text-warning", "price": 750 }, + "unpin": { + "kind": "unpin", + "title": "1-Hour Unpin", + "description": "Removes 1 hour from the pin duration of the post.", + "icon": "fas fa-thumbtack", + "color": "text-black", + "price": 1000 + }, } else: AWARDS = { @@ -229,6 +253,14 @@ def buy(v, award): "color": "text-warning", "price": 750 }, + "unpin": { + "kind": "unpin", + "title": "1-Hour Unpin", + "description": "Removes 1 hour from the pin duration of the post.", + "icon": "fas fa-thumbtack", + "color": "text-black", + "price": 1000 + }, } if award not in AWARDS: abort(400) @@ -337,6 +369,14 @@ def award_post(pid, v): post.stickied = f"t:{t}" g.db.add(post) cache.delete_memoized(frontlist) + elif kind == "unpin": + if not (post.stickied and post.stickied.startswith("t:")): abort(403) + t = int(post.stickied[2:]) - 3600 + if time.time() > t: + post.stickied = None + cache.delete_memoized(frontlist) + else: post.stickied = f"t:{t}" + g.db.add(post) post.author.received_award_count += 1 g.db.add(post.author) diff --git a/files/routes/posts.py b/files/routes/posts.py index e10532135..3fcbe9297 100755 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -515,11 +515,11 @@ def submit_post(v): # filtered = dict((k, v) for k, v in qd.items() if not k.startswith('utm_')) # new_url = ParseResult(scheme="https", - # netloc=parsed_url.netloc, - # path=parsed_url.path, - # params=parsed_url.params, - # query=urlencode(filtered, doseq=True), - # fragment=parsed_url.fragment) + # netloc=parsed_url.netloc, + # path=parsed_url.path, + # params=parsed_url.params, + # query=urlencode(filtered, doseq=True), + # fragment=parsed_url.fragment) # url = urlunparse(new_url) repost = g.db.query(Submission).options(lazyload('*')).filter( diff --git a/files/routes/settings.py b/files/routes/settings.py index 0ed828e20..95d5bc69e 100755 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -328,12 +328,15 @@ def gumroad(v): grant_awards["fireflies"] = 10 grant_awards["train"] = 10 grant_awards["ban"] = 5 + grant_awards["pin"] = 1 elif tier == 5 or tier == 8: if v.discord_id: add_role(v, "5") grant_awards["shit"] = 20 grant_awards["fireflies"] = 20 grant_awards["train"] = 20 grant_awards["ban"] = 10 + grant_awards["pin"] = 2 + grant_awards["unpin"] = 1 thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id diff --git a/files/templates/award_modal.html b/files/templates/award_modal.html index bdb25ffd3..7bc6ede8c 100755 --- a/files/templates/award_modal.html +++ b/files/templates/award_modal.html @@ -64,7 +64,7 @@ @media (min-width: 767.98px) { .award-columns { - column-count: 7 !important; + column-count: 8 !important; } } \ No newline at end of file diff --git a/files/templates/submission.html b/files/templates/submission.html index 9e9358c56..bdd62adb8 100755 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -823,10 +823,10 @@ window.localStorage.setItem("comment-counts", JSON.stringify(comments)) {% endif %} - {% if p.stickied %} + {% if p.stickied %} const pinned_info = document.getElementById('pinned-{{p.id}}') {% if p.stickied.startswith('t:') %} - pinned_info.setAttribute("data-bs-original-title", `Pinned until ${Date({{p.stickied[2:]}}).toString()}`) + pinned_info.setAttribute("data-bs-original-title", `Pinned until ${new Date({{p.stickied[2:]}} * 1000).toString()}`) {% else %} pinned_info.setAttribute("data-bs-original-title", "Pinned by @{{p.stickied}}") {%endif%}