本文整理汇总了Python中models.Post.update方法的典型用法代码示例。如果您正苦于以下问题:Python Post.update方法的具体用法?Python Post.update怎么用?Python Post.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Post
的用法示例。
在下文中一共展示了Post.update方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: feed_update
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import update [as 别名]
def feed_update(id=None):
# Manual update of one or all feeds now
if request.json['action'] == 'refresh':
# Call refresh routine
# TODO: RSS worker functions in separate package
# TODO: Need to capture return status
if id is None:
rss_spawn() # Update all feeds
else:
try:
feed = Feed.get(Feed.id == id)
except Feed.DoesNotExist:
return jsonify(**FEED_NOT_FOUND)
rss_worker(feed) # Update single feed
# return JSON status OK
return jsonify(**STATUS_OK)
# Mark one or all feeds read
elif request.json['action'] == 'markread':
if id is None:
# Mark all posts read
query = Post.update(is_read=True)
else:
# Mark posts in current feed read
query = Post.update(is_read=True).where(Feed.id == id)
query.execute()
# return JSON status OK
return jsonify(**STATUS_OK)
示例2: post_update_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import update [as 别名]
def post_update_post(id):
postid = request.forms.get('postid')
title = request.forms.get('title').decode('utf-8')
slug = request.forms.get('slug').decode('utf-8')
post = request.forms.get('post')
tags = request.forms.get('tags').decode('utf-8')
category = request.forms.get('category').decode('utf-8')
post_type = request.forms.get('postype')
if post_type == 'HTML':
is_html = 1
content = post.decode('utf-8')
markdown = u'html'
else:
is_html = 0
markdown = post.decode('utf-8')
content = to_markdown(markdown)
category = Category.get(name=category)
Post.update(title=title, slug=slug, content=content, markdown=markdown,
tags=tags, category=category,
is_html=is_html).where(id=postid).execute()
tag_list = set(tags.split(","))
for tag in tag_list:
try:
Tag.get(name=tag.strip(), post_id=postid)
except Post.DoesNotExist:
Tag.create(name=tag.strip(), post_id=postid)
redirect("/%s" % slug)
示例3: save_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import update [as 别名]
def save_post():
req_data = request.form
post_id = req_data.get('postId')
post_title = req_data.get('title')
post_content = req_data.get('content')
category_id = req_data.get('categoryId')
post_status = req_data.get('postStatus')
author_id = current_user.get_id()
if post_id is not None:
Post.update(author_id, post_title, post_content, post_status, category_id, post_id)
return jsonify(status='200', postId=post_id)
else:
post_id = Post.save(author_id, post_title, post_content, post_status, category_id)
return jsonify(status='200', postId=post_id)
示例4: edit_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import update [as 别名]
def edit_post(post_id):
"""Replaces post behind id with submitted one"""
post_d = mongo.db.posts.find_one(post_id)
if post_d is None:
abort(404)
form = PostEditForm.from_json(request.json, skip_unknown_keys=False)
if form.validate():
post = Post(bson=post_d)
post.update(form.data)
query = {'_id': post_id}
mongo.db.posts.update(query, post.to_bson())
# needed for chaining multiple edits together
token = generate_csrf_token()
return jsonify(_csrf=token, **post.to_dict())
else:
print form.errors #TODO
abort(400)
示例5: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import update [as 别名]
def post (identifier):
pageinfo = {
'title': 'post',
'heading': 'view post',
}
pageinfo = generate_pageinfo(pageinfo)
# This is probably dangerous; TODO: fix Post URL scheme.
post = Post().get({'_id': ObjectId(identifier)})
if post:
post = dict(post)
augment = {
'html': misaka.html(gfm.gfm(post['content'])),
'author': User().get({'_id': post['author']}),
}
post.update(augment)
pageinfo.update({'post': post, 'heading': post['title'], 'title': post['title']})
else:
flash('Post not found: {0}')
return render_template('post.html', pageinfo = pageinfo, models = models)
示例6: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import update [as 别名]
def post(self, postid):
title = self.get_argument('title', None)
slug = self.get_argument('slug', '')
category_id = self.get_argument('category', 1)
content = self.get_argument('content', '')
tags = self.get_argument('tag', '')
category = Category.get(id=int(category_id))
Post.update(title=title, slug=slug,
category=category, content=content, tags=tags).where(Post.id == postid).execute()
tag_list = set(tags.split(","))
if tag_list:
for tag in tag_list:
try:
Tag.get(name=tag, post=postid)
except Tag.DoesNotExist:
Tag.create(name=tag, post=postid)
self.redirect('/admin/posts')
return
示例7: set_favourite
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import update [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)