def post(self): title, summary, contents, image = self.getThese( "entry_title", "entry_summary", "entry_contents", "entry_image") user_name = get_current_username(self.request.cookies) user = get_user_entity_from_username(user_name) # Validate post and retrieve errors. error_messages = validate_blog_post(title, summary, contents, user_name) new_id = None if len(error_messages) == 0: # Create new blog post. post = BlogPost(title=title, owner=user, contents=contents, summary=summary, title_image=image if image != "" else None) post.put() new_id = post.key() # Render page with all required information. self.render("entry_new.html", True, new_id=new_id, error_messages=error_messages, entry_title=title, entry_summary=summary, entry_contents=contents)
def post(self, post_k): submitted = False post = db.get(post_k) title, summary, contents, image, delete_attachment = self.getThese( "entry-title", "entry-summary", "entry-contents", "entry_image", "remove-attachment") # Find entry for current user. user_name = get_current_username(self.request.cookies) current_user = get_user_entity_from_username(user_name) error_messages = [] if post.owner.key() == current_user.key(): # Validate post and return errors. error_messages = validate_blog_post( title, summary, contents, user_name) if len(error_messages) == 0: # Update post details. post.title = title post.summary = summary post.contents = contents # Only delete the attachment if the delete button was pressed. if delete_attachment == "0": post.title_image = image or post.title_image else: post.title_image = None post.put() submitted = True else: error_messages.append("You cannot edit someone else's blog post!") self.render( "entry_edit.html", True, submitted=submitted, post=post, entry_title=title, entry_summary=summary, entry_contents=contents, error_messages=error_messages)
def post(self, post_k): submitted = False post = db.get(post_k) title, summary, contents, image, delete_attachment = self.getThese( "entry-title", "entry-summary", "entry-contents", "entry_image", "remove-attachment") # Find entry for current user. user_name = get_current_username(self.request.cookies) current_user = get_user_entity_from_username(user_name) error_messages = [] if post.owner.key() == current_user.key(): # Validate post and return errors. error_messages = validate_blog_post(title, summary, contents, user_name) if len(error_messages) == 0: # Update post details. post.title = title post.summary = summary post.contents = contents # Only delete the attachment if the delete button was pressed. if delete_attachment == "0": post.title_image = image or post.title_image else: post.title_image = None post.put() submitted = True else: error_messages.append("You cannot edit someone else's blog post!") self.render("entry_edit.html", True, submitted=submitted, post=post, entry_title=title, entry_summary=summary, entry_contents=contents, error_messages=error_messages)
def post(self): title, summary, contents, image = self.getThese( "entry_title", "entry_summary", "entry_contents", "entry_image") user_name = get_current_username(self.request.cookies) user = get_user_entity_from_username(user_name) # Validate post and retrieve errors. error_messages = validate_blog_post( title, summary, contents, user_name) new_id = None if len(error_messages) == 0: # Create new blog post. post = BlogPost( title=title, owner=user, contents=contents, summary=summary, title_image=image if image != "" else None) post.put() new_id = post.key() # Render page with all required information. self.render( "entry_new.html", True, new_id=new_id, error_messages=error_messages, entry_title=title, entry_summary=summary, entry_contents=contents)