def post(self): # add new post or edit existed post t_values = {} current_post_id = self.request.POST["current_post_id"] post_title = self.request.POST["blog_title"] post_slug = get_safe_slug(self.request.POST["blog_slug"]) post_content = self.request.POST["blog_content"] # find category blog_category_id = self.request.POST["blog_category_id"] post_category = Category.get_by_id(long(blog_category_id)) if post_category: logging.info("find category %s for id %s" % (post_category.name, blog_category_id)) else: logging.error("category id %s can't be located" % (blog_category_id)) if current_post_id: logging.info("PostManager: post : edit post current_post_id = %s" % (current_post_id)) # update existed post post = Entry.get_by_id(long(current_post_id)) if post: t_values['alert_message'] = "Post %s has been updated!" % (post.title) post.title = post_title post.slug = post_slug post.content = post_content post.entrytype = "post" # update category count if this post is public if post.is_external_page and post.category != post_category: if post.category and (post.category.entrycount > 0): post.category.entrycount -= 1 post.category.put() post_category.entrycount += 1 post.category.put() post.category = post_category post.put() else: logging.info("PostManager: post : new post title %s" % (self.request.POST['blog_title'])) # create new post post = Entry() post.title = post_title post.slug = post_slug post.content = post_content post.entrytype = 'post' post.category = post_category # save as public or private? operation = self.request.POST["submit_action"] if operation == "save_publish": post.is_external_page = True # update category count post.category.entrycount += 1 post.category.put() else: # "save" operation post.is_external_page = False # save the post post.put() t_values['alert_message'] = "Post %s has been created!" % (post.title) # show all posts posts = Entry.all().filter("entrytype =", 'post') t_values['posts'] = posts return self.response.out.write(render_template("posts.html", t_values, "", True))
def post(self): t_values = {} # add new post or edit existed post current_post_id = self.request.POST["current_post_id"] if current_post_id: logging.info("PageManager: post : current_post_id = %s" % (current_post_id)) # update existed post post = Entry.get_by_id(long(current_post_id)) if post: t_values['alert_message'] = "Post %s has been updated!" % (post.title) post.title = self.request.POST["blog_title"] post.slug = get_safe_slug(self.request.POST["blog_slug"]) post.content = self.request.POST["blog_content"] post.entrytype = 'page' post.put() else: logging.info("PageManager: post : new post title %s" % (self.request.POST['blog_title'])) # create new post post = Entry() post.title = self.request.POST["blog_title"] post.slug = get_safe_slug(self.request.POST["blog_slug"]) post.content = self.request.POST["blog_content"] # post.categories = self.request.POST["blog_categories"] operation = self.request.POST["submit_action"] logging.info("operation = %s" % (operation)) if operation == "save_publish": post.is_external_page = True else: # "save" operation post.is_external_page = False post.entrytype = 'page' post.put() t_values['alert_message'] = "Page %s: %s has been created!" % (post.title, post.entrytype) # show all posts posts = Entry.all().filter("entrytype =", 'page') t_values['posts'] = posts return self.response.out.write(render_template("pages.html", t_values, "", True))