diff --git a/drama/classes/votes.py b/drama/classes/votes.py index 9f30c2921..56db6fba3 100644 --- a/drama/classes/votes.py +++ b/drama/classes/votes.py @@ -30,22 +30,6 @@ class Vote(Base): def __repr__(self): return f"" - def change_to(self, x): - """ - 1 - upvote - 0 - novote - -1 - downvote - """ - if x in ["-1", "0", "1"]: - x = int(x) - elif x not in [-1, 0, 1]: - abort(400) - - self.vote_type = x - self.created_utc = int(time()) - - g.db.add(self) - @property def json_core(self): data={ @@ -73,7 +57,6 @@ class CommentVote(Base): user_id = Column(Integer, ForeignKey("users.id")) vote_type = Column(Integer) comment_id = Column(Integer, ForeignKey("comments.id")) - created_utc = Column(Integer, default=0) app_id = Column(Integer, ForeignKey("oauth_apps.id")) user = relationship("User", lazy="subquery") @@ -89,22 +72,6 @@ class CommentVote(Base): def __repr__(self): return f"" - def change_to(self, x): - """ - 1 - upvote - 0 - novote - -1 - downvote - """ - if x in ["-1", "0", "1"]: - x = int(x) - elif x not in [-1, 0, 1]: - abort(400) - - self.vote_type = x - self.created_utc = int(time()) - - g.db.add(self) - @property def json_core(self): data={ diff --git a/drama/routes/votes.py b/drama/routes/votes.py index e754dca4f..b8d7ca77f 100644 --- a/drama/routes/votes.py +++ b/drama/routes/votes.py @@ -62,21 +62,21 @@ def admin_vote_info_get(v): -@app.route("/api/v1/vote/post//", methods=["POST"]) -@app.route("/api/vote/post//", methods=["POST"]) +@app.route("/api/v1/vote/post//", methods=["POST"]) +@app.route("/api/vote/post//", methods=["POST"]) @is_not_banned @api("vote") @validate_formkey -def api_vote_post(post_id, x, v): +def api_vote_post(post_id, new, v): - if x not in ["-1", "0", "1"]: abort(400) + if new not in ["-1", "0", "1"]: abort(400) # disallow bots if request.headers.get("X-User-Type","") == "Bot": abort(403) - x = int(x) + new = int(new) - if x==-1: + if new==-1: count=g.db.query(Vote).filter( Vote.user_id.in_( tuple( @@ -95,20 +95,24 @@ def api_vote_post(post_id, x, v): existing = g.db.query(Vote).filter_by(user_id=v.id, submission_id=post.id).first() if existing: - if existing == 0 and x != 0: + if v.id == 1: + print(existing) + print(new) + if existing == 0 and new != 0: + print('sex') post.author.dramacoins += 1 g.db.add(post.author) - elif existing != 0 and x == 0: + elif existing != 0 and new == 0: post.author.dramacoins -= 1 g.db.add(post.author) - existing.change_to(x) + existing.vote_type = new g.db.add(existing) else: - if x != 0: + if new != 0: post.author.dramacoins += 1 g.db.add(post.author) vote = Vote(user_id=v.id, - vote_type=x, + vote_type=new, submission_id=base36decode(post_id), app_id=v.client.application.id if v.client else None ) @@ -122,21 +126,21 @@ def api_vote_post(post_id, x, v): g.db.add(post) return "", 204 -@app.route("/api/v1/vote/comment//", methods=["POST"]) -@app.route("/api/vote/comment//", methods=["POST"]) +@app.route("/api/v1/vote/comment//", methods=["POST"]) +@app.route("/api/vote/comment//", methods=["POST"]) @is_not_banned @api("vote") @validate_formkey -def api_vote_comment(comment_id, x, v): +def api_vote_comment(comment_id, new, v): - if x not in ["-1", "0", "1"]: + if new not in ["-1", "0", "1"]: abort(400) # disallow bots if request.headers.get("X-User-Type","") == "Bot": abort(403) - x = int(x) + new = int(new) comment = get_comment(comment_id) @@ -144,16 +148,16 @@ def api_vote_comment(comment_id, x, v): existing = g.db.query(CommentVote).filter_by( user_id=v.id, comment_id=comment.id).first() if existing: - if existing == 0 and x != 0: + if existing == 0 and new != 0: comment.author.dramacoins += 1 g.db.add(comment.author) - elif existing != 0 and x == 0: + elif existing != 0 and new == 0: comment.author.dramacoins -= 1 g.db.add(comment.author) - existing.change_to(x) + existing.change_to(new) g.db.add(existing) else: - if x != 0: + if new != 0: comment.author.dramacoins += 1 g.db.add(comment.author) vote = CommentVote(user_id=v.id,