def get(self, id): post = Post.get_by_id(int(id)) if post is not None: comments = Comment.by_post(post) if post: self.render("post.html", post=post, comments=comments) else: self.redirect("/not-found") else: self.redirect("/not-found")
def post(self): """ Removes a post entry if user is authenticated, if no redirects to login route :return: """ post_id = self.request.get('id') post = Post.get_by_id(post_id) if Post.is_post_owner(self.request.cookies.get('user_id'), post): post.key.delete() time.sleep(2) self.redirect('/main')
def post(self): """ Creates a new comment in a post if user is authenticated, if no redirects to login route :return: """ post_id = self.request.get('id') comment = self.request.get('comment') user = User.get_by_hash(self.request.cookies.get('user_id')) post = Post.get_by_id(post_id) comment = Comment(author=user.user, post=post.key.id(), comment=comment, created=datetime.datetime.now(), last_modified=datetime.datetime.now()) comment.put() time.sleep(2) self.redirect('/main')
def post(self): """ Creates or update a new post entry if user is authenticated, if no redirects to login route :return: """ user_id = self.request.cookies.get('user_id') post_id = self.request.get('id') title = self.request.get('title') content = self.request.get('content') if 'update' in self.request.POST: post = Post.get_by_id(post_id) if Post.is_post_owner(user_id, post): post.title = title post.content = content post.last_modified = datetime.datetime.now() post.put() time.sleep(2) elif 'create' in self.request.POST: title = self.request.get('title') content = self.request.get('content') user = User.get_by_hash(user_id) p = Post(author=user.user, title=title, content=content, created=datetime.datetime.now(), last_modified=datetime.datetime.now()) p.put() time.sleep(2) self.redirect('/main')
def post(self): """ Creates a post like or unlike if user is authenticated, if no redirects to login route :return: """ user_id = self.request.cookies.get('user_id') post_id = self.request.get('id_post') user = User.get_by_hash(user_id) post = Post.get_by_id(post_id) if self.like_parameters_are_valid(user, post_id, post): if self.can_like(user, post): post.likes.append(user.user) post.put() elif self.can_unlike(user, post): post.likes.remove(user.user) post.put() time.sleep(2) self.redirect('/main')