remotes/1693045480750635534/spooky-22
Aevann1 2021-07-28 05:55:47 +02:00
parent 9feb860656
commit 06bc282d0b
6 changed files with 23 additions and 24 deletions

View File

@ -135,6 +135,9 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
@property @property
def json_raw(self): def json_raw(self):
flags = {}
for f in self.flags: flags[f.user.username] = f.reason
data= { data= {
'id': self.base36id, 'id': self.base36id,
'fullname': self.fullname, 'fullname': self.fullname,
@ -157,7 +160,7 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
'downvotes': self.downvotes_fuzzed, 'downvotes': self.downvotes_fuzzed,
#'award_count': self.award_count, #'award_count': self.award_count,
'is_bot': self.is_bot, 'is_bot': self.is_bot,
'flags': self.flags, 'flags': flags,
} }
if self.ban_reason: if self.ban_reason:

View File

@ -214,6 +214,9 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing):
@property @property
def json_raw(self): def json_raw(self):
flags = {}
for f in self.flags: flags[f.user.username] = f.reason
data = {'author_name': self.author.username, data = {'author_name': self.author.username,
'permalink': self.permalink, 'permalink': self.permalink,
'is_banned': bool(self.is_banned), 'is_banned': bool(self.is_banned),
@ -241,8 +244,9 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing):
'meta_title': self.meta_title, 'meta_title': self.meta_title,
'meta_description': self.meta_description, 'meta_description': self.meta_description,
'voted': self.voted, 'voted': self.voted,
'flags': self.flags, 'flags': flags,
} }
if self.ban_reason: if self.ban_reason:
data["ban_reason"]=self.ban_reason data["ban_reason"]=self.ban_reason

View File

@ -33,6 +33,8 @@ class User(Base, Stndrd, Age_times):
css = deferred(Column(String)) css = deferred(Column(String))
profilecss = deferred(Column(String)) profilecss = deferred(Column(String))
passhash = deferred(Column(String)) passhash = deferred(Column(String))
post_count = Column(Integer, default=0)
comment_count = Column(Integer, default=0)
banawards = Column(Integer, default=0) banawards = Column(Integer, default=0)
created_utc = Column(Integer, default=0) created_utc = Column(Integer, default=0)
suicide_utc = Column(Integer, default=0) suicide_utc = Column(Integer, default=0)
@ -331,16 +333,6 @@ class User(Base, Stndrd, Age_times):
Comment.is_banned == False, Comment.is_banned == False,
Comment.deleted_utc == 0).count() Comment.deleted_utc == 0).count()
@property
@lazy
def post_count(self):
return self.submissions.filter_by(is_banned=False, deleted_utc=0).count()
@property
@lazy
def comment_count(self):
return self.comments.filter(Comment.parent_submission != None).filter_by(is_banned=False, deleted_utc=0).count()
@property @property
@lazy @lazy
def alts(self): def alts(self):

View File

@ -60,7 +60,7 @@ def comment_cid_api_redirect(cid=None, pid=None):
@app.get("/post_short/<pid>/<cid>/") @app.get("/post_short/<pid>/<cid>/")
@app.get("/api/v1/comment/<cid>") @app.get("/api/v1/comment/<cid>")
@app.get("/post/<pid>/<anything>/<cid>") @app.get("/post/<pid>/<anything>/<cid>")
@app.route("/api/vue/comment/<cid>") @app.get("/api/vue/comment/<cid>")
@auth_desired @auth_desired
@api("read") @api("read")
def post_pid_comment_cid(cid, pid=None, anything=None, v=None): def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
@ -625,6 +625,9 @@ def api_comment(v):
cache.delete_memoized(comment_idlist) cache.delete_memoized(comment_idlist)
cache.delete_memoized(User.commentlisting, v) cache.delete_memoized(User.commentlisting, v)
v.comment_count = v.comments.filter(Comment.parent_submission != None).filter_by(is_banned=False, deleted_utc=0).count()
g.db.add(v)
return {"html": lambda: jsonify({"html": render_template("comments.html", return {"html": lambda: jsonify({"html": render_template("comments.html",
v=v, v=v,
comments=[c], comments=[c],
@ -843,8 +846,8 @@ def edit_comment(cid, v):
return jsonify({"html": c.body_html}) return jsonify({"html": c.body_html})
@app.route("/delete/comment/<cid>", methods=["GET", "POST"]) @app.post("/delete/comment/<cid>")
@app.route("/api/v1/delete/comment/<cid>", methods=["GET", "POST"]) @app.post("/api/v1/delete/comment/<cid>")
@auth_required @auth_required
@validate_formkey @validate_formkey
@api("delete") @api("delete")

View File

@ -373,7 +373,7 @@ def edit_post(pid, v):
return redirect(p.permalink) return redirect(p.permalink)
@app.route("/submit/title", methods=['GET']) @app.get("/submit/title")
@limiter.limit("6/minute") @limiter.limit("6/minute")
@is_not_banned @is_not_banned
def get_post_title(v): def get_post_title(v):
@ -549,7 +549,7 @@ def archiveorg(url):
except Exception as e: print(e) except Exception as e: print(e)
@app.route("/submit", methods=['POST']) @app.post("/submit")
@app.post("/api/v1/submit") @app.post("/api/v1/submit")
@app.post("/api/vue/submit") @app.post("/api/vue/submit")
@limiter.limit("6/minute") @limiter.limit("6/minute")
@ -1037,6 +1037,8 @@ def submit_post(v):
g.db.commit() g.db.commit()
send_message(f"https://rdrama.net{new_post.permalink}") send_message(f"https://rdrama.net{new_post.permalink}")
v.post_count = v.submissions.filter_by(is_banned=False, deleted_utc=0).count()
g.db.add(v)
return {"html": lambda: redirect(new_post.permalink), return {"html": lambda: redirect(new_post.permalink),
"api": lambda: jsonify(new_post.json) "api": lambda: jsonify(new_post.json)
} }

View File

@ -45,15 +45,10 @@ def leaderboard(v):
users = g.db.query(User).options(lazyload('*')) users = g.db.query(User).options(lazyload('*'))
users1 = users.order_by(User.dramacoins.desc()).limit(25).all() users1 = users.order_by(User.dramacoins.desc()).limit(25).all()
users2 = users.order_by(User.stored_subscriber_count.desc()).limit(10).all() users2 = users.order_by(User.stored_subscriber_count.desc()).limit(10).all()
users3, users4 = counts() users3 = users.order_by(User.post_count.desc()).limit(10).all()
users4 = users.order_by(User.comment_count.desc()).limit(10).all()
return render_template("leaderboard.html", v=v, users1=users1, users2=users2, users3=users3, users4=users4) return render_template("leaderboard.html", v=v, users1=users1, users2=users2, users3=users3, users4=users4)
@cache.memoize(timeout=86400)
def counts():
users3 = sorted(g.db.query(User).options(lazyload('*')).all(), key=lambda x: x.post_count, reverse=True)[:10]
users4 = sorted(g.db.query(User).options(lazyload('*')).all(), key=lambda x: x.comment_count, reverse=True)[:10]
return users3, users4
@app.get("/@<username>/css") @app.get("/@<username>/css")
def get_css(username): def get_css(username):
user = get_user(username) user = get_user(username)