forked from rDrama/rDrama
master
parent
8c4f1c8a6a
commit
35a1eea4ca
|
@ -181,6 +181,47 @@ class User(Base, Stndrd, Age_times):
|
||||||
def strid(self):
|
def strid(self):
|
||||||
return str(self.id)
|
return str(self.id)
|
||||||
|
|
||||||
|
@cache.memoize(timeout=86400)
|
||||||
|
def userpagelisting(self, v=None, page=1, sort="new", t="all"):
|
||||||
|
|
||||||
|
submissions = g.db.query(Submission).options(lazyload('*')).filter_by(author_id=self.id, is_pinned=False)
|
||||||
|
|
||||||
|
if not (v and (v.admin_level >= 3 or v.id == self.id)):
|
||||||
|
submissions = submissions.filter_by(deleted_utc=0, is_banned=False, private=False)
|
||||||
|
|
||||||
|
now = int(time.time())
|
||||||
|
if t == 'hour':
|
||||||
|
cutoff = now - 3600
|
||||||
|
elif t == 'day':
|
||||||
|
cutoff = now - 86400
|
||||||
|
elif t == 'week':
|
||||||
|
cutoff = now - 604800
|
||||||
|
elif t == 'month':
|
||||||
|
cutoff = now - 2592000
|
||||||
|
elif t == 'year':
|
||||||
|
cutoff = now - 31536000
|
||||||
|
else:
|
||||||
|
cutoff = 0
|
||||||
|
submissions = submissions.filter(Submission.created_utc >= cutoff)
|
||||||
|
|
||||||
|
if sort == "new":
|
||||||
|
submissions = submissions.order_by(Submission.created_utc.desc()).all()
|
||||||
|
elif sort == "old":
|
||||||
|
submissions = submissions.order_by(Submission.created_utc.asc()).all()
|
||||||
|
elif sort == "controversial":
|
||||||
|
submissions = sorted(submissions.all(), key=lambda x: x.score_disputed, reverse=True)
|
||||||
|
elif sort == "top":
|
||||||
|
submissions = sorted(submissions.all(), key=lambda x: x.score, reverse=True)
|
||||||
|
elif sort == "bottom":
|
||||||
|
submissions = sorted(submissions.all(), key=lambda x: x.score)
|
||||||
|
elif sort == "comments":
|
||||||
|
submissions = submissions.order_by(Submission.comment_count.desc()).all()
|
||||||
|
|
||||||
|
firstrange = 25 * (page - 1)
|
||||||
|
secondrange = firstrange + 26
|
||||||
|
listing = [x.id for x in submissions[firstrange:secondrange]]
|
||||||
|
return listing
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fullname(self):
|
def fullname(self):
|
||||||
return f"t1_{self.id}"
|
return f"t1_{self.id}"
|
||||||
|
|
|
@ -1085,6 +1085,7 @@ def submit_post(v):
|
||||||
g.db.add(v)
|
g.db.add(v)
|
||||||
|
|
||||||
cache.delete_memoized(frontlist)
|
cache.delete_memoized(frontlist)
|
||||||
|
cache.delete_memoized(User.userpagelisting)
|
||||||
if "[changelog]" in new_post.title or "(changelog)" in new_post.title:
|
if "[changelog]" in new_post.title or "(changelog)" in new_post.title:
|
||||||
send_message(f"https://{site}{new_post.permalink}")
|
send_message(f"https://{site}{new_post.permalink}")
|
||||||
cache.delete_memoized(changeloglist)
|
cache.delete_memoized(changeloglist)
|
||||||
|
|
|
@ -256,7 +256,7 @@ def changelogsub(v):
|
||||||
v.changelogsub = not v.changelogsub
|
v.changelogsub = not v.changelogsub
|
||||||
g.db.add(v)
|
g.db.add(v)
|
||||||
|
|
||||||
cache.delete_memoized(frontlist, v)
|
cache.delete_memoized(frontlist)
|
||||||
|
|
||||||
g.db.flush()
|
g.db.flush()
|
||||||
if v.changelogsub: return {"message": "You have subscribed to the changelog!"}
|
if v.changelogsub: return {"message": "You have subscribed to the changelog!"}
|
||||||
|
@ -641,7 +641,7 @@ def settings_block_user(v):
|
||||||
|
|
||||||
if v.admin_level == 1: return {"message": f"@{user.username} banned!"}
|
if v.admin_level == 1: return {"message": f"@{user.username} banned!"}
|
||||||
|
|
||||||
cache.delete_memoized(frontlist, v)
|
cache.delete_memoized(frontlist)
|
||||||
|
|
||||||
return {"message": f"@{user.username} blocked."}
|
return {"message": f"@{user.username} blocked."}
|
||||||
|
|
||||||
|
@ -666,7 +666,7 @@ def settings_unblock_user(v):
|
||||||
|
|
||||||
if v.admin_level == 1: return {"message": f"@{user.username} unbanned!"}
|
if v.admin_level == 1: return {"message": f"@{user.username} unbanned!"}
|
||||||
|
|
||||||
cache.delete_memoized(frontlist, v)
|
cache.delete_memoized(frontlist)
|
||||||
|
|
||||||
return {"message": f"@{user.username} unblocked."}
|
return {"message": f"@{user.username} unblocked."}
|
||||||
|
|
||||||
|
|
|
@ -414,43 +414,7 @@ def u_username(username, v=None):
|
||||||
page = int(request.args.get("page", "1"))
|
page = int(request.args.get("page", "1"))
|
||||||
page = max(page, 1)
|
page = max(page, 1)
|
||||||
|
|
||||||
|
ids = u.userpagelisting(v=v, page=page, sort=sort, t=t)
|
||||||
submissions = u.submissions.filter_by(is_pinned=False)
|
|
||||||
|
|
||||||
if not (v and (v.admin_level >= 3 or v.id == u.id)):
|
|
||||||
submissions = submissions.filter_by(deleted_utc=0, is_banned=False, private=False)
|
|
||||||
|
|
||||||
now = int(time.time())
|
|
||||||
if t == 'hour':
|
|
||||||
cutoff = now - 3600
|
|
||||||
elif t == 'day':
|
|
||||||
cutoff = now - 86400
|
|
||||||
elif t == 'week':
|
|
||||||
cutoff = now - 604800
|
|
||||||
elif t == 'month':
|
|
||||||
cutoff = now - 2592000
|
|
||||||
elif t == 'year':
|
|
||||||
cutoff = now - 31536000
|
|
||||||
else:
|
|
||||||
cutoff = 0
|
|
||||||
submissions = submissions.filter(Submission.created_utc >= cutoff)
|
|
||||||
|
|
||||||
if sort == "new":
|
|
||||||
submissions = submissions.order_by(Submission.created_utc.desc()).all()
|
|
||||||
elif sort == "old":
|
|
||||||
submissions = submissions.order_by(Submission.created_utc.asc()).all()
|
|
||||||
elif sort == "controversial":
|
|
||||||
submissions = sorted(submissions.all(), key=lambda x: x.score_disputed, reverse=True)
|
|
||||||
elif sort == "top":
|
|
||||||
submissions = sorted(submissions.all(), key=lambda x: x.score, reverse=True)
|
|
||||||
elif sort == "bottom":
|
|
||||||
submissions = sorted(submissions.all(), key=lambda x: x.score)
|
|
||||||
elif sort == "comments":
|
|
||||||
submissions = submissions.order_by(Submission.comment_count.desc()).all()
|
|
||||||
|
|
||||||
firstrange = 25 * (page - 1)
|
|
||||||
secondrange = firstrange + 26
|
|
||||||
ids = [x.id for x in submissions[firstrange:secondrange]]
|
|
||||||
|
|
||||||
# we got 26 items just to see if a next page exists
|
# we got 26 items just to see if a next page exists
|
||||||
next_exists = (len(ids) > 25)
|
next_exists = (len(ids) > 25)
|
||||||
|
|
Loading…
Reference in New Issue