当前位置: 首页>>代码示例>>Python>>正文


Python Document.put方法代码示例

本文整理汇总了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
开发者ID:frankk00,项目名称:latimes-document-stacker,代码行数:62,代码来源:__init__.py


注:本文中的documents.models.Document.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。