forked from MarseyWorld/MarseyWorld
order saved posts, comments and subscribed post by newest to oldest
parent
0b77e3f039
commit
1088e38f34
|
@ -10,6 +10,8 @@ class SaveRelationship(Base):
|
|||
user_id=Column(Integer, ForeignKey("users.id"), primary_key=True)
|
||||
submission_id=Column(Integer, ForeignKey("submissions.id"), primary_key=True)
|
||||
|
||||
post = relationship("Submission", uselist=False)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<SaveRelationship(user_id={self.user_id}, submission_id={self.submission_id})>"
|
||||
|
||||
|
@ -21,5 +23,7 @@ class CommentSaveRelationship(Base):
|
|||
user_id=Column(Integer, ForeignKey("users.id"), primary_key=True)
|
||||
comment_id=Column(Integer, ForeignKey("comments.id"), primary_key=True)
|
||||
|
||||
comment = relationship("Comment", uselist=False)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<CommentSaveRelationship(user_id={self.user_id}, comment_id={self.comment_id})>"
|
|
@ -8,6 +8,7 @@ class Subscription(Base):
|
|||
submission_id = Column(Integer, ForeignKey("submissions.id"), primary_key=True)
|
||||
|
||||
user = relationship("User", uselist=False)
|
||||
post = relationship("Submission", uselist=False)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
|
|
@ -693,19 +693,22 @@ class User(Base):
|
|||
def userblocks(self):
|
||||
return [x[0] for x in g.db.query(UserBlock.target_id).filter_by(user_id=self.id).all()]
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def saved_idlist(self, page=1):
|
||||
posts = g.db.query(SaveRelationship.submission_id).filter_by(user_id=self.id).offset(25 * (page - 1)).all()
|
||||
def saved_idlist(self):
|
||||
posts = g.db.query(SaveRelationship.submission_id).filter_by(user_id=self.id).all()
|
||||
return [x[0] for x in posts]
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def saved_comment_idlist(self, page=1):
|
||||
comments = g.db.query(CommentSaveRelationship.comment_id).filter_by(user_id=self.id).offset(25 * (page - 1)).all()
|
||||
def saved_comment_idlist(self):
|
||||
comments = g.db.query(CommentSaveRelationship.comment_id).filter_by(user_id=self.id).all()
|
||||
return [x[0] for x in comments]
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def subscribed_idlist(self, page=1):
|
||||
posts = g.db.query(Subscription.submission_id).filter_by(user_id=self.id)
|
||||
def subscribed_idlist(self):
|
||||
posts = g.db.query(Subscription.submission_id).filter_by(user_id=self.id).all()
|
||||
return [x[0] for x in posts]
|
||||
|
||||
|
||||
|
|
|
@ -1173,14 +1173,13 @@ def saved_posts(v, username):
|
|||
|
||||
page=int(request.values.get("page",1))
|
||||
|
||||
ids=v.saved_idlist(page=page)
|
||||
ids = [x[0] for x in g.db.query(SaveRelationship.submission_id).join(SaveRelationship.post).filter(SaveRelationship.user_id == v.id).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()]
|
||||
|
||||
next_exists=len(ids)>25
|
||||
|
||||
ids=ids[:25]
|
||||
|
||||
listing = get_posts(ids, v=v)
|
||||
listing.reverse()
|
||||
|
||||
if request.headers.get("Authorization"): return {"data": [x.json for x in listing]}
|
||||
return render_template("userpage.html",
|
||||
|
@ -1198,14 +1197,13 @@ def saved_comments(v, username):
|
|||
|
||||
page=int(request.values.get("page",1))
|
||||
|
||||
ids=v.saved_comment_idlist(page=page)
|
||||
ids = [x[0] for x in g.db.query(CommentSaveRelationship.comment_id).join(CommentSaveRelationship.comment).filter(CommentSaveRelationship.user_id == v.id).order_by(Comment.id.desc()).offset(25 * (page - 1)).limit(26).all()]
|
||||
|
||||
next_exists=len(ids) > 25
|
||||
|
||||
ids=ids[:25]
|
||||
|
||||
listing = get_comments(ids, v=v)
|
||||
listing.reverse()
|
||||
|
||||
if request.headers.get("Authorization"): return {"data": [x.json for x in listing]}
|
||||
return render_template("userpage_comments.html",
|
||||
|
@ -1222,14 +1220,13 @@ def subscribed_posts(v, username):
|
|||
|
||||
page=int(request.values.get("page",1))
|
||||
|
||||
ids=v.subscribed_idlist(page=page)
|
||||
ids = [x[0] for x in g.db.query(Subscription.submission_id).join(Subscription.post).filter(Subscription.user_id == v.id).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()]
|
||||
|
||||
next_exists=len(ids)>25
|
||||
|
||||
ids=ids[:25]
|
||||
|
||||
listing = get_posts(ids, v=v)
|
||||
listing.reverse()
|
||||
|
||||
if request.headers.get("Authorization"): return {"data": [x.json for x in listing]}
|
||||
return render_template("userpage.html",
|
||||
|
|
|
@ -122,7 +122,7 @@
|
|||
<span class="font-weight-bold">Comment {{'Replies' if (replies | length)>1 else 'Reply'}}: <a href="{{c.post.permalink}}">{{c.post.realtitle(v) | safe}}</a></span>
|
||||
{% elif c.post.author_id==v.id and c.level == 1 and is_notification_page%}
|
||||
<span class="font-weight-bold">Post Reply: <a href="{{c.post.permalink}}">{{c.post.realtitle(v) | safe}}</a></span>
|
||||
{% elif is_notification_page and c.parent_submission in v.subscribed_idlist() %}
|
||||
{% elif is_notification_page and c.parent_submission in v.subscribed_idlist %}
|
||||
<span class="font-weight-bold">Subscribed Thread: <a href="{{c.post.permalink}}">{{c.post.realtitle(v) | safe}}</a></span>
|
||||
{% elif is_notification_page %}
|
||||
<span class="font-weight-bold">Username Mention: <a href="{{c.post.permalink}}">{{c.post.realtitle(v) | safe}}</a></span>
|
||||
|
@ -450,9 +450,9 @@
|
|||
|
||||
<button class="btn caction py-0 nobackground px-1 text-muted" role="button" data-bs-toggle="modal" data-bs-target="#awardModal" data-url="/award/comment/{{c.id}}"><i class="fas fa-gift" aria-hidden="true"></i>Give Award</button>
|
||||
|
||||
<button id="unsave-{{c.id}}" class="btn caction py-0 nobackground px-1 {% if c.id in v.saved_comment_idlist() %}d-md-inline-block{% endif %} text-muted d-none" role="button" onclick="post_toast(this,'/unsave_comment/{{c.id}}','save-{{c.id}}','unsave-{{c.id}}','d-md-inline-block')"><i class="fas fa-save"></i>Unsave</button>
|
||||
<button id="unsave-{{c.id}}" class="btn caction py-0 nobackground px-1 {% if c.id in v.saved_comment_idlist %}d-md-inline-block{% endif %} text-muted d-none" role="button" onclick="post_toast(this,'/unsave_comment/{{c.id}}','save-{{c.id}}','unsave-{{c.id}}','d-md-inline-block')"><i class="fas fa-save"></i>Unsave</button>
|
||||
|
||||
<button id="save-{{c.id}}" class="btn caction py-0 nobackground px-1 {% if c.id not in v.saved_comment_idlist() %}d-md-inline-block{% endif %} text-muted d-none" role="button" onclick="post_toast(this,'/save_comment/{{c.id}}','save-{{c.id}}','unsave-{{c.id}}','d-md-inline-block')"><i class="fas fa-save"></i>Save</button>
|
||||
<button id="save-{{c.id}}" class="btn caction py-0 nobackground px-1 {% if c.id not in v.saved_comment_idlist %}d-md-inline-block{% endif %} text-muted d-none" role="button" onclick="post_toast(this,'/save_comment/{{c.id}}','save-{{c.id}}','unsave-{{c.id}}','d-md-inline-block')"><i class="fas fa-save"></i>Save</button>
|
||||
{% endif %}
|
||||
|
||||
{% if c.parent_submission %}
|
||||
|
@ -655,9 +655,9 @@
|
|||
|
||||
<a class="list-group-item" role="button" data-bs-toggle="modal" data-bs-target="#awardModal" data-url="/award/comment/{{c.id}}"><i class="fas fa-gift mr-2" aria-hidden="true"></i>Give Award</a>
|
||||
|
||||
<a id="save2-{{c.id}}" class="list-group-item {% if c.id in v.saved_comment_idlist() %}d-none{% endif %}" role="button" data-bs-dismiss="modal" onclick="post_toast(this,'/save_comment/{{c.id}}','save2-{{c.id}}','unsave2-{{c.id}}','d-none')"><i class="fas fa-save mr-2"></i>Save</a>
|
||||
<a id="save2-{{c.id}}" class="list-group-item {% if c.id in v.saved_comment_idlist %}d-none{% endif %}" role="button" data-bs-dismiss="modal" onclick="post_toast(this,'/save_comment/{{c.id}}','save2-{{c.id}}','unsave2-{{c.id}}','d-none')"><i class="fas fa-save mr-2"></i>Save</a>
|
||||
|
||||
<a id="unsave2-{{c.id}}" class="list-group-item {% if c.id not in v.saved_comment_idlist() %}d-none{% endif %}" role="button" onclick="post_toast(this,'/unsave_comment/{{c.id}}','save2-{{c.id}}','unsave2-{{c.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-save mr-2"></i>Unsave</a>
|
||||
<a id="unsave2-{{c.id}}" class="list-group-item {% if c.id not in v.saved_comment_idlist %}d-none{% endif %}" role="button" onclick="post_toast(this,'/unsave_comment/{{c.id}}','save2-{{c.id}}','unsave2-{{c.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-save mr-2"></i>Unsave</a>
|
||||
|
||||
{% if c.author_id == v.id %}
|
||||
<a role="button" data-bs-dismiss="modal" onclick="toggleEdit('{{c.id}}')" class="list-group-item"><i class="fas fa-edit mr-2"></i>Edit</a>
|
||||
|
|
|
@ -15,13 +15,13 @@
|
|||
<a class="list-inline-item copy-link" role="button" data-clipboard-text="{% if SITE == 'rdrama.net' %}https://chapotraphouse.club{{p.shortlink}}{% else %}{{p.permalink}}{% endif %}"><i class="fas fa-copy"></i>Copy link</a>
|
||||
|
||||
{% if v %}
|
||||
<a id="subscribe-{{p.id}}" class="{% if p.id in v.subscribed_idlist() %}d-none{% endif %} list-inline-item" role="button" onclick="post_toast(this,'/subscribe/{{p.id}}','subscribe-{{p.id}}','unsubscribe-{{p.id}}','d-none')"><i class="fas fa-eye"></i>Subscribe</a>
|
||||
<a id="unsubscribe-{{p.id}}" class="{% if p.id not in v.subscribed_idlist() %}d-none{% endif %} list-inline-item" role="button" onclick="post_toast(this,'/unsubscribe/{{p.id}}','subscribe-{{p.id}}','unsubscribe-{{p.id}}','d-none')"><i class="fas fa-eye-slash"></i>Unsubscribe</a>
|
||||
<a id="subscribe-{{p.id}}" class="{% if p.id in v.subscribed_idlist %}d-none{% endif %} list-inline-item" role="button" onclick="post_toast(this,'/subscribe/{{p.id}}','subscribe-{{p.id}}','unsubscribe-{{p.id}}','d-none')"><i class="fas fa-eye"></i>Subscribe</a>
|
||||
<a id="unsubscribe-{{p.id}}" class="{% if p.id not in v.subscribed_idlist %}d-none{% endif %} list-inline-item" role="button" onclick="post_toast(this,'/unsubscribe/{{p.id}}','subscribe-{{p.id}}','unsubscribe-{{p.id}}','d-none')"><i class="fas fa-eye-slash"></i>Unsubscribe</a>
|
||||
{% endif %}
|
||||
|
||||
{% if v %}
|
||||
<a id="save-{{p.id}}" class="{% if p.id in v.saved_idlist() %}d-none{% endif %} list-inline-item" role="button" onclick="post_toast(this,'/save_post/{{p.id}}','save-{{p.id}}','unsave-{{p.id}}','d-none')"><i class="fas fa-save"></i>Save</a>
|
||||
<a id="unsave-{{p.id}}" class="{% if not p.id in v.saved_idlist() %}d-none{% endif %} list-inline-item" role="button" onclick="post_toast(this,'/unsave_post/{{p.id}}','save-{{p.id}}','unsave-{{p.id}}','d-none')"><i class="fas fa-save"></i>Unsave</a>
|
||||
<a id="save-{{p.id}}" class="{% if p.id in v.saved_idlist %}d-none{% endif %} list-inline-item" role="button" onclick="post_toast(this,'/save_post/{{p.id}}','save-{{p.id}}','unsave-{{p.id}}','d-none')"><i class="fas fa-save"></i>Save</a>
|
||||
<a id="unsave-{{p.id}}" class="{% if not p.id in v.saved_idlist %}d-none{% endif %} list-inline-item" role="button" onclick="post_toast(this,'/unsave_post/{{p.id}}','save-{{p.id}}','unsave-{{p.id}}','d-none')"><i class="fas fa-save"></i>Unsave</a>
|
||||
|
||||
<a class="list-inline-item" role="button" data-bs-toggle="modal" data-bs-dismiss="modal" data-bs-target="#reportPostModal" onclick="report_postModal('{{p.id}}')"><i class="fas fa-flag"></i>Report</a>
|
||||
{% endif %}
|
||||
|
|
|
@ -14,11 +14,11 @@
|
|||
|
||||
<button class="nobackground btn btn-link btn-block btn-lg text-left text-muted" data-bs-toggle="modal" data-bs-dismiss="modal" data-bs-target="#awardModal" data-url='/award/post/{{p.id}}'><i class="fas fa-gift text-center text-muted mr-3"></i>Give Award</button>
|
||||
|
||||
<button id="subscribe2-{{p.id}}" class="{% if p.id in v.subscribed_idlist() %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-muted" role="button" onclick="post_toast(this,'/subscribe/{{p.id}}','subscribe2-{{p.id}}','unsubscribe2-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-eye text-center text-muted mr-3"></i>Subscribe</button>
|
||||
<button id="unsubscribe2-{{p.id}}" class="{% if not p.id in v.subscribed_idlist() %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-muted" role="button" onclick="post_toast(this,'/unsubscribe/{{p.id}}','subscribe2-{{p.id}}','unsubscribe2-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-eye-slash text-center text-muted mr-3"></i>Unsubscribe</button>
|
||||
<button id="subscribe2-{{p.id}}" class="{% if p.id in v.subscribed_idlist %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-muted" role="button" onclick="post_toast(this,'/subscribe/{{p.id}}','subscribe2-{{p.id}}','unsubscribe2-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-eye text-center text-muted mr-3"></i>Subscribe</button>
|
||||
<button id="unsubscribe2-{{p.id}}" class="{% if not p.id in v.subscribed_idlist %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-muted" role="button" onclick="post_toast(this,'/unsubscribe/{{p.id}}','subscribe2-{{p.id}}','unsubscribe2-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-eye-slash text-center text-muted mr-3"></i>Unsubscribe</button>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
|
|
Loading…
Reference in New Issue