本文整理汇总了Python中models.Tags.update方法的典型用法代码示例。如果您正苦于以下问题:Python Tags.update方法的具体用法?Python Tags.update怎么用?Python Tags.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Tags
的用法示例。
在下文中一共展示了Tags.update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_post
# 需要导入模块: from models import Tags [as 别名]
# 或者: from models.Tags import update [as 别名]
def edit_post(id):
form = PostForm()
if users.is_current_user_admin() and form.validate_on_submit():
tags = Tags()
categories = Categories()
updating_post = BlogPost.get(int(id))
title = request.json['title']
body = request.json['body']
raw_category = request.json['category']
editing_tags = request.json['tags']
raw_summary = request.json['summary']
tags_keys = tags.update(editing_tags, updating_post)
category_key = categories.update(raw_category, updating_post.category)
updating_post.edit(title, body, datetime.now(), tags_keys,
category_key, raw_summary, raw_answers=request.json['answers'])
return jsonify(updating_post.to_json()) # dangerous
示例2: delete_post
# 需要导入模块: from models import Tags [as 别名]
# 或者: from models.Tags import update [as 别名]
def delete_post(id):
if users.is_current_user_admin():
posts = Posts()
tags = Tags()
categories = Categories()
updating_post = BlogPost.get(int(id))
categories.delete(updating_post.category)
posts.delete(updating_post.key)
tags.update(updating_post.get_tag_names())
return jsonify(msg="OK")
示例3: main
# 需要导入模块: from models import Tags [as 别名]
# 或者: from models.Tags import update [as 别名]
def main():
if users.is_current_user_admin():
if request.method=='GET': #all entitites
posts = Posts()
return jsonify(posts.to_json())
elif request.method == "POST":
form = PostForm()
if form.validate_on_submit(): #new entity
posts = Posts()
categories = Categories()
tags = Tags()
raw_post = request.get_json()
raw_category = raw_post["category"]
editing_tags = raw_post["tags"]
raw_summary = raw_post["summary"]
tag_keys = tags.update(editing_tags)
category_key = categories.update(raw_category)
post_id = posts.add(raw_title=raw_post["title"],
raw_body=raw_post["body"],
category_key=category_key,
tags_ids=tag_keys,
summary=raw_summary,
answers=raw_post["answers"]).id()
post = BlogPost.get(post_id)
return jsonify(post.to_json()) # Needs check
else:
return jsonify(msg="missing token")
else:
return jsonify({})