forked from rDrama/rDrama
add new pagination to notifs
parent
b6e27f29b9
commit
b80e42f156
|
@ -1,6 +1,7 @@
|
|||
import time
|
||||
|
||||
from sqlalchemy.sql.expression import not_, and_, or_
|
||||
from sqlalchemy.orm import load_only
|
||||
|
||||
from files.classes.mod_logs import ModAction
|
||||
from files.classes.sub_logs import SubAction
|
||||
|
@ -298,12 +299,9 @@ def notifications(v:User):
|
|||
Comment.is_banned != False,
|
||||
Comment.deleted_utc != 0,
|
||||
)
|
||||
).all()
|
||||
for n in unread_and_inaccessible:
|
||||
n.read = True
|
||||
g.db.add(n)
|
||||
).update({Notification.read: True})
|
||||
|
||||
comments = g.db.query(Comment, Notification).join(Notification.comment).filter(
|
||||
comments = g.db.query(Comment, Notification).options(load_only(Comment.id)).join(Notification.comment).filter(
|
||||
Notification.user_id == v.id,
|
||||
or_(Comment.sentto == None, Comment.sentto != v.id),
|
||||
)
|
||||
|
@ -320,10 +318,9 @@ def notifications(v:User):
|
|||
)
|
||||
|
||||
comments = comments.order_by(Notification.created_utc.desc(), Comment.id.desc())
|
||||
comments = comments.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE+1).all()
|
||||
next_exists = comments.count()
|
||||
comments = comments.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
|
||||
|
||||
next_exists = (len(comments) > PAGE_SIZE)
|
||||
comments = comments[:PAGE_SIZE]
|
||||
cids = [x[0].id for x in comments]
|
||||
|
||||
listing = []
|
||||
|
@ -413,4 +410,5 @@ def notifications(v:User):
|
|||
page=page,
|
||||
standalone=True,
|
||||
render_replies=True,
|
||||
size=PAGE_SIZE,
|
||||
)
|
||||
|
|
|
@ -131,25 +131,7 @@
|
|||
|
||||
{% block pagenav %}
|
||||
{% if notifications %}
|
||||
<nav>
|
||||
<ul class="pagination pagination-sm mb-0 mt-4">
|
||||
{% if page>1 %}
|
||||
<li class="page-item">
|
||||
<small><a class="page-link" href="{{request.path}}?page={{page-1}}">Previous</a></small>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled"><span class="page-link">Prev</span></li>
|
||||
{% endif %}
|
||||
|
||||
{% if next_exists %}
|
||||
<li class="page-item">
|
||||
<small><a class="page-link" href="{{request.path}}?page={{page+1}}">Next</a></small>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled"><span class="page-link">Next</span></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
{% include "pagination.html" %}
|
||||
{% endif %}
|
||||
|
||||
<link rel="stylesheet" href="{{('css/notifications.css') | asset}}">
|
||||
|
|
Loading…
Reference in New Issue