本文整理汇总了Python中model.Entry.entrytype方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.entrytype方法的具体用法?Python Entry.entrytype怎么用?Python Entry.entrytype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Entry
的用法示例。
在下文中一共展示了Entry.entrytype方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from model import Entry [as 别名]
# 或者: from model.Entry import entrytype [as 别名]
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))