本文整理汇总了Python中documents.models.Document.put方法的典型用法代码示例。如果您正苦于以下问题:Python Document.put方法的具体用法?Python Document.put怎么用?Python Document.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类documents.models.Document
的用法示例。
在下文中一共展示了Document.put方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_or_create_document
# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import put [as 别名]
def update_or_create_document(yaml_obj):
"""
Submit an object read from our YAML files and it will update it in the
database, creating it if it doesn't already exist.
Returns the database object, and a boolean that is true if a new object
was created.
"""
# Check if the table already exists in the datastore
obj = Document.get_by_key_name(yaml_obj.get('slug'))
# Update the obj if it exists
if obj:
# Loop through the keys and update the object one by one.
for key in yaml_obj.keys():
# With some special casing for projects...
if key == 'project_slug':
proj = Project.get_by_key_name(yaml_obj.get('project_slug'))
obj.project = proj
# ...and for tags.
elif key == 'tags':
obj.tags = get_tag_keys(yaml_obj.get("tags"))
else:
setattr(obj, key, yaml_obj.get(key))
# Save it out
obj.put()
created = False
# Create it if it doesn't
else:
# If it has tags....
if yaml_obj.has_key('tags'):
# Convert to database keys
tags = get_tag_keys(yaml_obj.pop("tags"))
# Load the data
obj = Document(key_name=yaml_obj.get('slug'), **yaml_obj)
# Set the tags
obj.tags = tags
# Otherwise....
else:
# Update the basic values
obj = Document(key_name=yaml_obj.get('slug'), **yaml_obj)
# And clear out the tag data
obj.tags = []
obj.similar_documents = []
# Connected it to a project, if it exists
if yaml_obj.has_key('project_slug'):
proj = Project.get_by_key_name(yaml_obj.get('project_slug'))
obj.project = proj
# Save it out
obj.put()
created = True
# Update the similarity lists of documents with the same tags
taskqueue.add(
url='/_/document/update-similar/',
params=dict(key=obj.key()),
method='GET'
)
# Pass it out
return obj, created