def post(self): if utils.is_loggedIn(self): edit_comment = self.request.get('edit-comment') comment_userid = self.request.get('comment-userid') comment_id = self.request.get('comment-id') comment_editted = self.request.get('comment_editted') commentedit_userid = self.request.get('commentedit_userid') commentedit_key = self.request.get('commentedit_key') comment_content = self.request.get('comment_content') if edit_comment and comment_userid == utils.get_userID(self): key = db.Key.from_path('Comment', long(comment_id)) comment = db.get(key) if comment: self.render("edit-comment.html", comment=comment.content, is_logged_in=True, comment_userid=comment_userid, key=key) elif comment_editted and commentedit_userid == utils.get_userID( self): comment = db.get(commentedit_key) if comment and comment_content: comment.content = comment_content comment.put() self.redirect('/blog') else: self.render("edit-comment.html", comment=comment.content, is_logged_in=True, comment_userid=commentedit_userid, key=commentedit_key, error="comment can't be empty") else: self.response.out.write("in else")
def post(self): if utils.is_loggedIn(self): content = self.request.get('content') post_id = self.request.get('post-id') like = self.request.get('like') unlike = self.request.get('unlike') del_post = self.request.get('delete-post') del_comment = self.request.get('delete-comment') post_userid = self.request.get('post-userid') comment_userid = self.request.get('comment-userid') comment_id = self.request.get('comment-id') if content: comment = Comment(post_id=post_id, content=content, user_name=get_username(self), user_id=utils.get_userID(self)) comment.put() self.redirect('/blog') elif like and post_userid != utils.get_userID(self): like = Likes(post_id=post_id, user_id=utils.get_userID(self)) like.put() self.redirect('/blog') elif unlike and post_userid != utils.get_userID(self): likes = db.GqlQuery("SELECT * FROM Likes WHERE post_id =:1", post_id) for like in likes: if like.user_id == utils.get_userID(self): like.delete() self.redirect('/blog') elif del_post and post_userid == utils.get_userID(self): key = db.Key.from_path('Post', long(post_id)) old_post = db.get(key) comments = db.GqlQuery( "SELECT * FROM Comment WHERE post_id =:1", post_id) likes = db.GqlQuery("SELECT * FROM Likes WHERE post_id =:1", post_id) if old_post: db.delete(comments) db.delete(likes) db.delete(old_post) self.redirect('/blog') elif del_comment and comment_userid == utils.get_userID(self): key = db.Key.from_path('Comment', long(comment_id)) comment = db.get(key) if comment: db.delete(comment) self.redirect('/blog') else: self.response.out.write(post_userid)
def get(self): if utils.is_loggedIn(self): posts = db.GqlQuery("SELECT * FROM Post ORDER BY created DESC") comments = db.GqlQuery("SELECT * FROM Comment") likes = db.GqlQuery("SELECT * FROM Likes") self.render("front.html", is_logged_in=True, posts=posts, comments=comments, user_id=utils.get_userID(self), likes=likes) else: self.redirect('/welcome')
def post(self): if utils.is_loggedIn(self): subject = self.request.get("subject") content = self.request.get("content") if subject and content: post = Post(subject=subject, content=content, user_id=utils.get_userID(self)) post.put() self.redirect('/blog') else: message = "something is missing!" self.render("newpost.html", subject=subject, content=content, error=message, is_logged_in=True)
def post(self): if utils.is_loggedIn(self): post_userid = self.request.get('post-userid') post_id = self.request.get('post-id') post_editted = self.request.get('post-editted') posteditted_userid = self.request.get('post_userid') post_subject = self.request.get('post_subject') post_content = self.request.get('post_content') post_key = self.request.get('key') edit_post = self.request.get('edit-post') if edit_post and post_userid == utils.get_userID(self): key = db.Key.from_path('Post', long(post_id)) post = db.get(key) if post: self.render("edit-post.html", subject=post.subject, content=post.content, is_logged_in=True, post_userid=post_userid, key=key) elif post_editted and posteditted_userid == utils.get_userID(self): post = db.get(post_key) if post and post_subject and post_content: post.subject = post_subject post.content = post_content post.put() self.redirect('/blog') else: self.render("edit-post.html", subject=post_subject, content=post_content, is_logged_in=True, post_userid=posteditted_userid, key=post_key, error="something is missing!") else: self.response.out.write("in edit-post post method")
def get_username(self): if utils.is_loggedIn(self): key = db.Key.from_path('User', long(utils.get_userID(self))) user = db.get(key) user_name = user.name return user_name
def get(self): if utils.is_loggedIn(self): self.render("newpost.html", is_logged_in=True) else: self.redirect('/login')
def get(self): if not utils.is_loggedIn(self): self.render("signup-form.html") else: self.redirect('/welcome')