本文整理汇总了Python中models.Post.get方法的典型用法代码示例。如果您正苦于以下问题:Python Post.get方法的具体用法?Python Post.get怎么用?Python Post.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Post
的用法示例。
在下文中一共展示了Post.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get [as 别名]
def edit_post(id):
if request.forms.update_post :
post = Post.get(id=id)
post.title = request.forms.title
post.content = request.forms.content
post.save()
redirect('/view')
else :
post = Post.get(id=id)
return template('templates/edit.html.tpl',post=post)
示例2: view_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get [as 别名]
def view_post(id):
form = request.forms
if form.update_comment :
post = Post.get(id=id)
comment = Comment()
comment.post = post # current post
comment.user = User.get(username=form.username)
comment.content = form.content
comment.pub_date = datetime.now()
comment.save()
redirect('/view/post/%d' %(id,))
else :
post = Post.get(id=id)
comments = Comment.filter(post__id = id)
return template('templates/post.html.tpl',post=post,comments=comments)
示例3: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get [as 别名]
def post(postname):
post = Post.get(Post.header == postname)
return render_template('post.html', post=post,
posts=get_posts(),
categories=get_categories(),
recent_posts=get_posts(),
archives=get_archive())
示例4: get_update_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get [as 别名]
def get_update_post(id):
category = Category.select()
try:
post = Post.get(id=id)
except Post.DoesNotExist:
abort(404)
return template("admin/update.html", post=post, category=category)
示例5: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get [as 别名]
def post(self):
postid = self.get_argument('comment_post_ID')
author = self.get_argument('author',None)
email = self.get_argument('email',None)
url = self.get_argument('url',None)
comment = self.get_argument('comment',None)
parent_id = self.get_argument('comment_parent',None)
if postid:
post = Post.get(id=int(postid))
if author and email and comment:
if len(author) >18:
self.flash('UserName is too long.')
return self.redirect("%s#respond"%(post.url))
if not _email_re.match(email):
self.flash(u'Email address is invalid.')
return self.redirect("%s#respond"%(post.url))
if url and not _url_re.match(url):
self.flash(u'website is invalid.')
return self.redirect("%s#respond"%(post.url))
comment = Comment.create(post=post,ip=self.request.remote_ip,
author=author,email=email,website=url,
content=comment,parent_id=parent_id)
self.set_cookie('comment_author',author)
self.set_cookie('comment_email',email)
self.set_cookie('comment_website',url)
return self.redirect(comment.url)
else:
self.flash(u"请填写必要信息(姓名和电子邮件和评论内容)")
return self.redirect("%s#respond"%(post.url))
示例6: edit_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get [as 别名]
def edit_post(id):
username = request.get_cookie('admin', secret='some-secret-key')
if username:
if request.forms.update_post:
edit_post = Post.get(Post.id==id)
edit_post.title = request.forms.title
edit_post.content = request.forms.editor1
edit_post.save()
redirect ('/admin')
else:
edit_post = Post.get(Post.id==id)
title = edit_post.title
content = edit_post.content
return template('templates/edit_content.tpl', title=title, content=content)
else:
redirect('/login')
示例7: delete_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get [as 别名]
def delete_post(id):
#pdb.set_trace()
try:
post = Post.get(id=id)
post.delete_instance()
return template('templates/view.html.tpl')
except :
redirect('/view')
示例8: get
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get [as 别名]
def get(self, postid):
try:
post = Post.get(id=postid)
except Post.DoesNotExist:
raise tornado.web.HTTPError(404)
category = Category.select()
self.render('admin/post/update.html', post=post, category=category)
示例9: view_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get [as 别名]
def view_post(request, post_id):
post = Post.get(post_id)
form = CommentForm(request.POST or None)
if request.POST:
if form.is_valid():
form.cleaned_data['post'] = post_id
form.save()
comments = Comment.view('blog_app/comments_by_post', key=post_id)
示例10: get
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get [as 别名]
def get(self,page=1):
p = self.get_argument('p',None)
if p:
post = Post.get(id=int(p))
post.readnum += 1
post.save()
self.render('post.html',post=post)
else:
pagination = Pagination(Post.select(),int(page),per_page=8)
self.render('index.html',pagination=pagination)
示例11: set_favourite
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get [as 别名]
def set_favourite(id=None):
# Toggle favourite status for post #id
try:
is_favourite = Post.get(Post.id == id).is_favourite
query = Post.update(is_favourite=not is_favourite).where(Post.id == id)
query.execute()
except Post.DoesNotExist:
return jsonify(**POST_NOT_FOUND)
# return JSON status OK
return jsonify(**STATUS_OK)
示例12: edit_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get [as 别名]
def edit_post(request, post_id):
post = Post.get(post_id)
form = PostForm(request.POST or None, instance=post)
if form.is_valid():
post = form.save()
return render_to_response("post_edit.html", {
"form": form,
"post": post
}, context_instance=RequestContext(request))
示例13: show
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get [as 别名]
def show(request,key):
"""Request / -- show all posts."""
user = users.GetCurrentUser()
try:
post=Post.get(db.Key(unquote(key)))
if post is None:
return http.HttpResponseNotFound("No Post exists with that key")
return views.respond(request, user, 'posts/show',
{'post': post.to_hash()})
except(db.BadKeyError):
return http.HttpResponseNotFound("No Post exists with that key")
示例14: post_new_comment
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get [as 别名]
def post_new_comment():
postid = request.forms.get('postid')
name = request.forms.get('name').decode('utf-8')
email = request.forms.get('email').decode('utf-8')
url = request.forms.get('url').decode('utf-8')
content = request.forms.get('content').decode('utf-8')
parent = request.forms.get('parentid')
check = request.forms.get('check')
if check != "123456":
post = Post.get(id=postid)
redirect("/%s" % post.slug)
post = Post.get(id=postid)
post.comm_count = post.comm_count + 1
comment = Comment.create(post=post, author=escape(name),
email=escape(email), url=escape(url),
content=escape(content), parent=parent,
published=datetime.datetime.now())
post.save()
redirect("/%s#comment-%s" % (post.slug, comment.id))
示例15: get_favourite
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get [as 别名]
def get_favourite(id=None):
# Get favourite status for post #id
try:
fav = Post.get(Post.id == id)
except Post.DoesNotExist:
return jsonify(**POST_NOT_FOUND)
# return post fav status as JSON
resp = jsonify(fav.is_favourite)
resp.status_code = 200
return resp