def post(self, post_id): post = Post.by_id(int(post_id)) subject = self.request.get('subject') content = self.request.get('content') # check if we have both subject and content if subject and content: # check if the user is the post owner or somebody cheating if post.user.key().id() == self.uid(): post.subject = subject post.content = content post.put() self.redirect('/') # if something is missing, let's show it to the user else: error = 'Sorry, we need both, title and content.' self.render('edit-post.html', post=post, user=self.user, error=error)
def post(self, post_id): post = Post.by_id(int(post_id)) subject = self.request.get('subject') content = self.request.get('content') # check if we have both subject and content if subject and content: # check if the user is the post owner or somebody cheating if post.user.key().id() == self.uid(): post.subject = subject post.content = content post.put() self.redirect('/') # if something is missing, let's show it to the user else: error = 'Sorry, we need both, title and content.' self.render( 'edit-post.html', post=post, user=self.user, error=error )
def post(self): # somebody is trying to vote, let's check if is logged in if self.user: post = Post.by_id(int(self.request.get('post_id'))) user = self.user vote = int(self.request.get('vote')) # prepare the new vote new_vote = Vote(post=post, user=user, vote=vote) # check the user has not voted on this post before no_vote = True votes = Vote.by_post(post) for v in votes: # if user has already voted then False if v.user.key().id() == self.uid(): no_vote = False # has not voted before, let's put the vote if no_vote: new_vote.put() self.redirect('/') # not logged in, let's go to the login page else: self.redirect('/login')