fddf
This commit is contained in:
parent
4430dee142
commit
45409d5980
6 changed files with 23 additions and 24 deletions
|
@ -135,6 +135,9 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
|
|||
|
||||
@property
|
||||
def json_raw(self):
|
||||
flags = {}
|
||||
for f in self.flags: flags[f.user.username] = f.reason
|
||||
|
||||
data= {
|
||||
'id': self.base36id,
|
||||
'fullname': self.fullname,
|
||||
|
@ -157,7 +160,7 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
|
|||
'downvotes': self.downvotes_fuzzed,
|
||||
#'award_count': self.award_count,
|
||||
'is_bot': self.is_bot,
|
||||
'flags': self.flags,
|
||||
'flags': flags,
|
||||
}
|
||||
|
||||
if self.ban_reason:
|
||||
|
|
|
@ -214,6 +214,9 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing):
|
|||
@property
|
||||
|
||||
def json_raw(self):
|
||||
flags = {}
|
||||
for f in self.flags: flags[f.user.username] = f.reason
|
||||
|
||||
data = {'author_name': self.author.username,
|
||||
'permalink': self.permalink,
|
||||
'is_banned': bool(self.is_banned),
|
||||
|
@ -241,8 +244,9 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing):
|
|||
'meta_title': self.meta_title,
|
||||
'meta_description': self.meta_description,
|
||||
'voted': self.voted,
|
||||
'flags': self.flags,
|
||||
'flags': flags,
|
||||
}
|
||||
|
||||
if self.ban_reason:
|
||||
data["ban_reason"]=self.ban_reason
|
||||
|
||||
|
|
|
@ -33,6 +33,8 @@ class User(Base, Stndrd, Age_times):
|
|||
css = deferred(Column(String))
|
||||
profilecss = deferred(Column(String))
|
||||
passhash = deferred(Column(String))
|
||||
post_count = Column(Integer, default=0)
|
||||
comment_count = Column(Integer, default=0)
|
||||
banawards = Column(Integer, default=0)
|
||||
created_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.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
|
||||
@lazy
|
||||
def alts(self):
|
||||
|
|
|
@ -60,7 +60,7 @@ def comment_cid_api_redirect(cid=None, pid=None):
|
|||
@app.get("/post_short/<pid>/<cid>/")
|
||||
@app.get("/api/v1/comment/<cid>")
|
||||
@app.get("/post/<pid>/<anything>/<cid>")
|
||||
@app.route("/api/vue/comment/<cid>")
|
||||
@app.get("/api/vue/comment/<cid>")
|
||||
@auth_desired
|
||||
@api("read")
|
||||
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(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",
|
||||
v=v,
|
||||
comments=[c],
|
||||
|
@ -843,8 +846,8 @@ def edit_comment(cid, v):
|
|||
|
||||
return jsonify({"html": c.body_html})
|
||||
|
||||
@app.route("/delete/comment/<cid>", methods=["GET", "POST"])
|
||||
@app.route("/api/v1/delete/comment/<cid>", methods=["GET", "POST"])
|
||||
@app.post("/delete/comment/<cid>")
|
||||
@app.post("/api/v1/delete/comment/<cid>")
|
||||
@auth_required
|
||||
@validate_formkey
|
||||
@api("delete")
|
||||
|
|
|
@ -373,7 +373,7 @@ def edit_post(pid, v):
|
|||
|
||||
return redirect(p.permalink)
|
||||
|
||||
@app.route("/submit/title", methods=['GET'])
|
||||
@app.get("/submit/title")
|
||||
@limiter.limit("6/minute")
|
||||
@is_not_banned
|
||||
def get_post_title(v):
|
||||
|
@ -549,7 +549,7 @@ def archiveorg(url):
|
|||
except Exception as e: print(e)
|
||||
|
||||
|
||||
@app.route("/submit", methods=['POST'])
|
||||
@app.post("/submit")
|
||||
@app.post("/api/v1/submit")
|
||||
@app.post("/api/vue/submit")
|
||||
@limiter.limit("6/minute")
|
||||
|
@ -1037,6 +1037,8 @@ def submit_post(v):
|
|||
g.db.commit()
|
||||
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),
|
||||
"api": lambda: jsonify(new_post.json)
|
||||
}
|
||||
|
|
|
@ -45,15 +45,10 @@ def leaderboard(v):
|
|||
users = g.db.query(User).options(lazyload('*'))
|
||||
users1 = users.order_by(User.dramacoins.desc()).limit(25).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)
|
||||
|
||||
@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")
|
||||
def get_css(username):
|
||||
user = get_user(username)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue