本文整理汇总了Python中blog.models.BlogPost.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python BlogPost.get_by_id方法的具体用法?Python BlogPost.get_by_id怎么用?Python BlogPost.get_by_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.BlogPost
的用法示例。
在下文中一共展示了BlogPost.get_by_id方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: decorate
# 需要导入模块: from blog.models import BlogPost [as 别名]
# 或者: from blog.models.BlogPost import get_by_id [as 别名]
def decorate(self, post_id=None):
post = None
if post_id:
post = BlogPost.get_by_id(int(post_id))
if not post:
raise NotFound
return fun(self, post)
示例2: post_delete
# 需要导入模块: from blog.models import BlogPost [as 别名]
# 或者: from blog.models.BlogPost import get_by_id [as 别名]
def post_delete(request, post_id):
post = BlogPost.get_by_id(int(post_id))
user = users.get_current_user()
if request.method == "POST" and post.author == user.email():
post.key.delete()
return redirect("home")
else:
return redirect("forbidden")
示例3: generate_resource
# 需要导入模块: from blog.models import BlogPost [as 别名]
# 或者: from blog.models.BlogPost import get_by_id [as 别名]
def generate_resource(cls, post, resource):
from blog.models import BlogPost
if not post:
post = BlogPost.get_by_id(resource)
else:
assert resource == post.key().id()
template_vals = {
'post': post,
'config': config,
}
template_name = "blog/themes/%s/post.html" % config.theme
rendered = utils.render_template(template_name, template_vals)
StaticContent.set(post.path, rendered, config.html_mime_type)
示例4: post_edit
# 需要导入模块: from blog.models import BlogPost [as 别名]
# 或者: from blog.models.BlogPost import get_by_id [as 别名]
def post_edit(request, post_id):
post = BlogPost.get_by_id(int(post_id))
user = users.get_current_user()
if request.method == "GET" and post.author == user.email():
form = BlogPostForm({"title": post.title, "content": post.content})
params = {"form": form, "post": post}
return blog_render(request, "post_edit.html", params)
elif request.method == "POST" and post.author == user.email():
form = BlogPostForm(request.POST)
if form.is_valid():
BlogPost.edit(post_id=int(post_id),
title=form.cleaned_data["title"],
content=form.cleaned_data["content"])
else:
params = {"form": form}
return blog_render(request, "post_add.html", params)
return redirect("home")
else:
return redirect("forbidden")
示例5: post_view
# 需要导入模块: from blog.models import BlogPost [as 别名]
# 或者: from blog.models.BlogPost import get_by_id [as 别名]
def post_view(request, post_id):
post = BlogPost.get_by_id(int(post_id))
params = {"post": post}
return blog_render(request, "post_view.html", params)
示例6: get_blog_post
# 需要导入模块: from blog.models import BlogPost [as 别名]
# 或者: from blog.models.BlogPost import get_by_id [as 别名]
def get_blog_post(blog_post_id):
return BlogPost.get_by_id(int(blog_post_id))