fd
This commit is contained in:
parent
48bccbac06
commit
413e065824
4 changed files with 46 additions and 40 deletions
|
@ -181,6 +181,47 @@ class User(Base, Stndrd, Age_times):
|
|||
def strid(self):
|
||||
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
|
||||
def fullname(self):
|
||||
return f"t1_{self.id}"
|
||||
|
|
|
@ -1085,6 +1085,7 @@ def submit_post(v):
|
|||
g.db.add(v)
|
||||
|
||||
cache.delete_memoized(frontlist)
|
||||
cache.delete_memoized(User.userpagelisting)
|
||||
if "[changelog]" in new_post.title or "(changelog)" in new_post.title:
|
||||
send_message(f"https://{site}{new_post.permalink}")
|
||||
cache.delete_memoized(changeloglist)
|
||||
|
|
|
@ -256,7 +256,7 @@ def changelogsub(v):
|
|||
v.changelogsub = not v.changelogsub
|
||||
g.db.add(v)
|
||||
|
||||
cache.delete_memoized(frontlist, v)
|
||||
cache.delete_memoized(frontlist)
|
||||
|
||||
g.db.flush()
|
||||
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!"}
|
||||
|
||||
cache.delete_memoized(frontlist, v)
|
||||
cache.delete_memoized(frontlist)
|
||||
|
||||
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!"}
|
||||
|
||||
cache.delete_memoized(frontlist, v)
|
||||
cache.delete_memoized(frontlist)
|
||||
|
||||
return {"message": f"@{user.username} unblocked."}
|
||||
|
||||
|
|
|
@ -414,43 +414,7 @@ def u_username(username, v=None):
|
|||
page = int(request.args.get("page", "1"))
|
||||
page = max(page, 1)
|
||||
|
||||
|
||||
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]]
|
||||
ids = u.userpagelisting(v=v, page=page, sort=sort, t=t)
|
||||
|
||||
# we got 26 items just to see if a next page exists
|
||||
next_exists = (len(ids) > 25)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue