forked from rDrama/rDrama
add hole pinning
parent
fe22eefe41
commit
f56be06eb8
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -530,3 +530,31 @@ def sub_inactive_purge_task():
|
|||
g.db.delete(x)
|
||||
|
||||
return True
|
||||
|
||||
@app.post("/hole_pin/<pid>")
|
||||
@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/<pid>")
|
||||
@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}"}
|
||||
|
|
|
@ -50,6 +50,11 @@
|
|||
<a id="unpin-{{p.id}}" class="dropdown-item {% if not p.stickied %}d-none{% endif %} list-inline-item text-info" role="button" onclick="post_toast(this,'/unsticky/{{p.id}}','pin-{{p.id}}','unpin-{{p.id}}','d-none')"><i class="fas fa-thumbtack fa-rotate--45"></i>Unpin</a>
|
||||
{% endif %}
|
||||
|
||||
{% if p.sub and v.mods(p.sub) %}
|
||||
<a id="hole-pin-{{p.id}}" class="dropdown-item {% if p.hole_pinned %}d-none{% endif %} list-inline-item text-info" role="button" onclick="post_toast(this,'/hole_pin/{{p.id}}','hole-pin-{{p.id}}','hole-unpin-{{p.id}}','d-none')"><i class="fas fa-thumbtack fa-rotate--45"></i>Pin to /h/{{p.sub}}</a>
|
||||
<a id="hole-unpin-{{p.id}}" class="dropdown-item {% if not p.hole_pinned %}d-none{% endif %} list-inline-item text-info" role="button" onclick="post_toast(this,'/hole_unpin/{{p.id}}','hole-pin-{{p.id}}','hole-unpin-{{p.id}}','d-none')"><i class="fas fa-thumbtack fa-rotate--45"></i>Unpin fron /h/{{p.sub}}</a>
|
||||
{% endif %}
|
||||
|
||||
{% if v.admin_level > 1 or v.id == p.author_id %}
|
||||
<a id="club-{{p.id}}" class="dropdown-item {% if p.club %}d-none{% endif %} list-inline-item text-info" role="button" onclick="post_toast(this,'/toggle_club/{{p.id}}','club-{{p.id}}','unclub-{{p.id}}','d-none')"><i class="fas fa-eye-slash"></i>Mark club</a>
|
||||
<a id="unclub-{{p.id}}" class="dropdown-item {% if not p.club %}d-none{% endif %} list-inline-item text-info" role="button" onclick="post_toast(this,'/toggle_club/{{p.id}}','club-{{p.id}}','unclub-{{p.id}}','d-none')"><i class="fas fa-eye"></i>Unmark club</a>
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
<button id="save2-{{p.id}}" class="{% if p.id in v.saved_idlist() %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-muted" role="button" onclick="post_toast(this,'/save_post/{{p.id}}','save2-{{p.id}}','unsave2-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-save text-center text-muted mr-3"></i>Save</button>
|
||||
<button id="unsave2-{{p.id}}" class="{% if not p.id in v.saved_idlist() %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-muted" role="button" onclick="post_toast(this,'/unsave_post/{{p.id}}','save2-{{p.id}}','unsave2-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-save text-center text-muted mr-3"></i>Unsave</button>
|
||||
|
||||
{% if p.sub and v.mods(p.sub) %}
|
||||
<button id="hole-pin2-{{p.id}}" class="{% if p.hole_pinned %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-muted" role="button" onclick="post_toast(this,'/hole_pin/{{p.id}}','hole-pin2-{{p.id}}','hole-unpin2-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-thumbtack fa-rotate--45 text-center text-muted mr-3"></i>Pin to /h/{{p.sub}}</button>
|
||||
<button id="hole-unpin2-{{p.id}}" class="{% if not p.hole_pinned %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-muted" role="button" onclick="post_toast(this,'/hole_unpin/{{p.id}}','hole-pin2-{{p.id}}','hole-unpin2-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-thumbtack fa-rotate--45 text-center text-muted mr-3"></i>Unpin from /h/{{p.sub}}</button>
|
||||
{% endif %}
|
||||
|
||||
{% if v.id==p.author_id %}
|
||||
{% if request.path.startswith('/@') %}
|
||||
|
|
|
@ -730,6 +730,10 @@
|
|||
<i id='pinned-{{p.id}}' class="fas fa-thumbtack fa-rotate--45 text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Pinned by @{{p.stickied}}" {% if p.stickied_utc %}onmouseover="pinned_timestamp('pinned-{{p.id}}')" data-timestamp={{p.stickied_utc}} {% endif %}></i>
|
||||
{% endif %}
|
||||
|
||||
{% if p.hole_pinned %}
|
||||
<i id='hole-pinned-{{p.id}}' class="fas fa-thumbtack fa-rotate--45 text-blue" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Pinned to /h/{{p.sub}} by @{{p.hole_pinned}}"></i>
|
||||
{% endif %}
|
||||
|
||||
{% if p.is_pinned %}<i class="fas fa-thumbtack fa-rotate--45 fa-fw text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Pinned to profile"></i>{% endif %}
|
||||
{% if p.distinguish_level %} <i class="fas fa-broom text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{SITE_NAME}} Admin, speaking officially"></i>{% endif %}
|
||||
{% if p.is_bot %} <i class="fas fa-robot text-info" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Bot"></i>{% endif %}
|
||||
|
|
|
@ -178,6 +178,10 @@
|
|||
<i id='pinned-{{p.id}}' class="fas fa-thumbtack fa-rotate--45 text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Pinned by @{{p.stickied}}" {% if p.stickied_utc %}onmouseover="pinned_timestamp('pinned-{{p.id}}')" data-timestamp={{p.stickied_utc}} {% endif %}></i>
|
||||
{% endif %}
|
||||
|
||||
{% if p.hole_pinned %}
|
||||
<i id='hole-pinned-{{p.id}}' class="fas fa-thumbtack fa-rotate--45 text-blue" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Pinned to /h/{{p.sub}} by @{{p.hole_pinned}}"></i>
|
||||
{% endif %}
|
||||
|
||||
{% if p.distinguish_level %}<i class="fas fa-broom text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{SITE_NAME}} Admin, speaking officially"></i>{% endif %}
|
||||
{% if p.is_pinned and request.path.startswith('/@') %}<i class="fas fa-thumbtack fa-rotate--45 text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Pinned to profile"></i>{% endif %}
|
||||
{% if p.over_18 %}<span class="badge badge-danger text-small-extra mr-1">+18</span>{% endif %}
|
||||
|
|
Loading…
Reference in New Issue