本文整理汇总了Python中pulp.server.db.model.content.ContentType._id方法的典型用法代码示例。如果您正苦于以下问题:Python ContentType._id方法的具体用法?Python ContentType._id怎么用?Python ContentType._id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pulp.server.db.model.content.ContentType
的用法示例。
在下文中一共展示了ContentType._id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_or_update_type
# 需要导入模块: from pulp.server.db.model.content import ContentType [as 别名]
# 或者: from pulp.server.db.model.content.ContentType import _id [as 别名]
def _create_or_update_type(type_def):
"""
This method creates or updates a type definition in MongoDB.
:param type_def: the type definition to update or create. If a type definition with the same
as an existing type, the type is updated, otherwise it is created.
:type type_def: ContentType
:return: This method will always return None
:rtype: None
"""
# Make sure a collection exists for the type
database = pulp_db.get_database()
collection_name = unit_collection_name(type_def.id)
if collection_name not in database.collection_names():
pulp_db.get_collection(collection_name, create=True)
# Add or update an entry in the types list
content_type_collection = ContentType.get_collection()
content_type = ContentType(
type_def.id, type_def.display_name, type_def.description, type_def.unit_key,
type_def.search_indexes, type_def.referenced_types)
# no longer rely on _id = id
existing_type = content_type_collection.find_one({'id': type_def.id}, fields=[])
if existing_type is not None:
content_type._id = existing_type['_id']
# XXX this still causes a potential race condition when 2 users are updating the same type
content_type_collection.save(content_type, safe=True)
示例2: _create_or_update_type
# 需要导入模块: from pulp.server.db.model.content import ContentType [as 别名]
# 或者: from pulp.server.db.model.content.ContentType import _id [as 别名]
def _create_or_update_type(type_def):
# Make sure a collection exists for the type
database = pulp_db.get_database()
collection_name = unit_collection_name(type_def.id)
if collection_name not in database.collection_names():
pulp_db.get_collection(collection_name, create=True)
# Add or update an entry in the types list
content_type_collection = ContentType.get_collection()
content_type = ContentType(type_def.id, type_def.display_name, type_def.description,
type_def.unit_key, type_def.search_indexes, type_def.referenced_types)
# no longer rely on _id = id
existing_type = content_type_collection.find_one({'id': type_def.id}, fields=[])
if existing_type is not None:
content_type._id = existing_type['_id']
# XXX this still causes a potential race condition when 2 users are updating the same type
content_type_collection.save(content_type, safe=True)