forked from rDrama/rDrama
fdfd
parent
332e79a107
commit
7118a4a0d6
|
@ -213,27 +213,10 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
|
|||
|
||||
return data
|
||||
|
||||
|
||||
@property
|
||||
def voted(self):
|
||||
|
||||
x = self.__dict__.get("_voted")
|
||||
if x != None:
|
||||
return x
|
||||
|
||||
if g.v:
|
||||
x = g.db.query(CommentVote).filter_by(
|
||||
comment_id=self.id,
|
||||
user_id=g.v.id
|
||||
).first()
|
||||
|
||||
if x:
|
||||
x = x.vote_type
|
||||
else:
|
||||
x = 0
|
||||
else:
|
||||
x = 0
|
||||
return x
|
||||
def voted(self, v):
|
||||
x = g.db.query(CommentVote).filter_by(comment_id=self.id, user_id=g.v.id).first()
|
||||
if x: return x.vote_type
|
||||
else: return 0
|
||||
|
||||
@property
|
||||
def is_blocking(self):
|
||||
|
|
|
@ -179,42 +179,20 @@ def get_posts(pids, v=None):
|
|||
|
||||
def get_comment(cid, v=None, graceful=False, **kwargs):
|
||||
|
||||
if isinstance(cid, str):
|
||||
i = base36decode(cid)
|
||||
else:
|
||||
i = cid
|
||||
if isinstance(cid, str): i = base36decode(cid)
|
||||
else: i = cid
|
||||
|
||||
if v:
|
||||
blocking = v.blocking.subquery()
|
||||
blocked = v.blocked.subquery()
|
||||
vt = g.db.query(CommentVote).filter(
|
||||
CommentVote.user_id == v.id,
|
||||
CommentVote.comment_id == i).subquery()
|
||||
|
||||
items = g.db.query(
|
||||
Comment,
|
||||
vt.c.vote_type,
|
||||
)
|
||||
items = g.db.query(Comment)
|
||||
|
||||
if v.admin_level >=4:
|
||||
items=items.options(joinedload(Comment.oauth_app))
|
||||
if v.admin_level >=4: items=items.options(joinedload(Comment.oauth_app))
|
||||
|
||||
items=items.filter(
|
||||
Comment.id == i
|
||||
).join(
|
||||
vt,
|
||||
vt.c.comment_id == Comment.id,
|
||||
isouter=True
|
||||
).join(
|
||||
Comment.post,
|
||||
isouter=True
|
||||
).first()
|
||||
x=items.filter(Comment.id == i).first()
|
||||
|
||||
if not items and not graceful:
|
||||
abort(404)
|
||||
|
||||
x = items[0]
|
||||
x._voted = items[1] or 0
|
||||
if not x and not graceful: abort(404)
|
||||
|
||||
block = g.db.query(UserBlock).filter(
|
||||
or_(
|
||||
|
@ -232,75 +210,23 @@ def get_comment(cid, v=None, graceful=False, **kwargs):
|
|||
x._is_blocked = block and block.target_id == v.id
|
||||
|
||||
else:
|
||||
x = g.db.query(
|
||||
Comment,
|
||||
).filter(Comment.id == i).first()
|
||||
|
||||
if not x and not graceful:
|
||||
abort(404)
|
||||
|
||||
x = g.db.query(Comment).filter(Comment.id == i).first()
|
||||
if not x and not graceful:abort(404)
|
||||
|
||||
return x
|
||||
|
||||
|
||||
def get_comments(cids, v=None, load_parent=False, **kwargs):
|
||||
def get_comments(cids, v=None, **kwargs):
|
||||
|
||||
if not cids:
|
||||
return []
|
||||
if not cids: return []
|
||||
|
||||
cids=tuple(cids)
|
||||
|
||||
if v:
|
||||
vt = g.db.query(CommentVote).filter(
|
||||
CommentVote.comment_id.in_(cids),
|
||||
CommentVote.user_id==v.id
|
||||
).subquery()
|
||||
output = g.db.query(Comment)
|
||||
|
||||
query = g.db.query(
|
||||
Comment,
|
||||
aliased(CommentVote, alias=vt),
|
||||
)
|
||||
if v and v.admin_level >=4: output=output.options(joinedload(Comment.oauth_app))
|
||||
|
||||
if v.admin_level >=4:
|
||||
query=query.options(joinedload(Comment.oauth_app))
|
||||
|
||||
if load_parent:
|
||||
query = query.options(
|
||||
joinedload(
|
||||
Comment.parent_comment
|
||||
)
|
||||
)
|
||||
|
||||
query = query.join(
|
||||
vt,
|
||||
vt.c.comment_id == Comment.id,
|
||||
isouter=True
|
||||
).join(
|
||||
Comment.post,
|
||||
isouter=True
|
||||
).filter(
|
||||
Comment.id.in_(cids)
|
||||
)
|
||||
|
||||
|
||||
output = [x[0] for x in query]
|
||||
for i in range(len(output)):
|
||||
if query[i][1] != None:
|
||||
try: output[i]._voted = query[i][1].vote_type
|
||||
except:
|
||||
print(query[i][1])
|
||||
output[i]._voted = 0
|
||||
else: output[i]._voted = 0
|
||||
|
||||
|
||||
else:
|
||||
query = g.db.query(
|
||||
Comment,
|
||||
).filter(
|
||||
Comment.id.in_(cids)
|
||||
).all()
|
||||
|
||||
output=[x for x in query]
|
||||
output = output.options(joinedload(Comment.parent_comment)).filter(Comment.id.in_(cids)).all()
|
||||
|
||||
output = sorted(output, key=lambda x: cids.index(x.id))
|
||||
|
||||
|
|
|
@ -29,12 +29,12 @@ def notifications(v):
|
|||
cids = v.notification_subscriptions(page=page, all_=all_)
|
||||
next_exists = (len(cids) == 26)
|
||||
cids = cids[:25]
|
||||
comments = get_comments(cids, v=v, sort="new", load_parent=True)
|
||||
comments = get_comments(cids, v=v, sort="new")
|
||||
else:
|
||||
cids = v.notification_commentlisting(page=page, all_=all_)
|
||||
next_exists = (len(cids) == 26)
|
||||
cids = cids[:25]
|
||||
comments = get_comments(cids, v=v, sort="new", load_parent=True)
|
||||
comments = get_comments(cids, v=v, sort="new")
|
||||
|
||||
listing = []
|
||||
for c in comments:
|
||||
|
|
|
@ -69,12 +69,10 @@
|
|||
{% set score=c.score %}
|
||||
|
||||
{% if v %}
|
||||
{% set voted=c.voted %}
|
||||
{% set adjust = voted %}
|
||||
{% set voted=c.voted(v) %}
|
||||
|
||||
{% else %}
|
||||
{% set voted=-2 %}
|
||||
{% set adjust=0 %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
|
|
Loading…
Reference in New Issue