def post(self, video_id): content = self.request.get("content") vote = self.request.get("vote") user = self.get_user() user_id = user["model_id"] if content: c = VideoComment( content=content, video_id=int(video_id), upvotes=0, submitter=user["username"], user_id=user_id, downvotes=0, ) c.put() video = Video.get_by_id(int(video_id)) video.comment_count = video.comment_count + 1 video.put() currentregistereduser = User.get_by_id(int(user["model_id"])) currentregistereduser.prestige = currentregistereduser.prestige + 2 currentregistereduser.put() # video_comment_cache(int(group_id), True) self.redirect("/video/%s" % video_id) elif vote: keyname = str(user_id) + "-" + str(video_id) + "-post" previous_vote = Vote.get_by_id(keyname) # previous_vote = Vote.get_by_key_name(keyname) if previous_vote != None: video = Video.get_by_id(int(video_id)) vote_count = video.upvotes - video.downvotes self.response.write(vote_count) else: vote_record = Vote.get_or_insert(keyname, vote_record=str(user_id)) video = Video.get_by_id(int(video_id)) vote_count = video.upvotes - video.downvotes if vote == "upvote": vote_count = vote_count + 1 video.upvotes = video.upvotes + 1 video.put() currentregistereduser = User.get_by_id(int(video.user_id)) currentregistereduser.prestige = currentregistereduser.prestige + 1 currentregistereduser.put() elif vote == "downvote": vote_count = vote_count - 1 video.downvotes = video.downvotes + 1 video.put() self.response.write(vote_count) else: something = "nada"
def get(self): user = self.get_user() if user["model_id"] == 5187942536445952: user_model = User.get_by_id(5187942536445952) user_model.admin = True user_model.put all_videos = Video.query() video_count = 0 for v in all_videos: video_count = video_count + 1 all_users = User.query() user_count = 0 for u in all_users: user_count = user_count + 1 all_comments = VideoComment.query() comment_count = 0 for c in all_comments: comment_count = comment_count + 1 all_votes = Vote.query() vote_count = 0 for vs in all_votes: vote_count = vote_count + 1 self.response.write("There are " + str(video_count) + " videos.") self.response.write("<br>") self.response.write("There are " + str(user_count) + " users.") self.response.write("<br>") self.response.write("There are " + str(comment_count) + " comments.") self.response.write("<br>") self.response.write("There are " + str(vote_count) + " votes.") else: self.redirect("/noaccess")