本文整理汇总了Python中website.project.model.MetaSchema.find方法的典型用法代码示例。如果您正苦于以下问题:Python MetaSchema.find方法的具体用法?Python MetaSchema.find怎么用?Python MetaSchema.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类website.project.model.MetaSchema
的用法示例。
在下文中一共展示了MetaSchema.find方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_metaschemas
# 需要导入模块: from website.project.model import MetaSchema [as 别名]
# 或者: from website.project.model.MetaSchema import find [as 别名]
def get_metaschemas(*args, **kwargs):
"""
List metaschemas with which a draft registration may be created. Only fetch the newest version for each schema.
:return: serialized metaschemas
:rtype: dict
"""
count = request.args.get('count', 100)
include = request.args.get('include', 'latest')
meta_schema_collection = database['metaschema']
meta_schemas = []
if include == 'latest':
schema_names = meta_schema_collection.distinct('name')
for name in schema_names:
meta_schema_set = MetaSchema.find(
Q('name', 'eq', name) &
Q('schema_version', 'eq', 2)
)
meta_schemas = meta_schemas + [s for s in meta_schema_set]
else:
meta_schemas = MetaSchema.find()
meta_schemas = [
schema
for schema in meta_schemas
if schema.name in ACTIVE_META_SCHEMAS
]
meta_schemas.sort(key=lambda a: ACTIVE_META_SCHEMAS.index(a.name))
return {
'meta_schemas': [
serialize_meta_schema(ms) for ms in meta_schemas[:count]
]
}, http.OK
示例2: test_ensure_schemas
# 需要导入模块: from website.project.model import MetaSchema [as 别名]
# 或者: from website.project.model.MetaSchema import find [as 别名]
def test_ensure_schemas(self):
# Should be zero MetaSchema records to begin with
assert_equal(
MetaSchema.find().count(),
0
)
ensure_schemas()
assert_equal(
MetaSchema.find().count(),
len(OSF_META_SCHEMAS)
)
示例3: _create
# 需要导入模块: from website.project.model import MetaSchema [as 别名]
# 或者: from website.project.model.MetaSchema import find [as 别名]
def _create(cls, *args, **kwargs):
branched_from = kwargs.get("branched_from")
initiator = kwargs.get("initiator")
registration_schema = kwargs.get("registration_schema")
registration_metadata = kwargs.get("registration_metadata")
if not branched_from:
project_params = {}
if initiator:
project_params["creator"] = initiator
branched_from = ProjectFactory(**project_params)
initiator = branched_from.creator
try:
registration_schema = registration_schema or MetaSchema.find()[0]
except IndexError:
ensure_schemas()
registration_metadata = registration_metadata or {}
draft = DraftRegistration.create_from_node(
branched_from, user=initiator, schema=registration_schema, data=registration_metadata
)
return draft
示例4: get_schema
# 需要导入模块: from website.project.model import MetaSchema [as 别名]
# 或者: from website.project.model.MetaSchema import find [as 别名]
def get_schema():
all_schemas = MetaSchema.find()
serialized_schemas = {
'schemas': [utils.serialize_meta_schema(s) for s in all_schemas]
}
return serialized_schemas
示例5: test_metaschema_is_fine_with_same_name_but_different_version
# 需要导入模块: from website.project.model import MetaSchema [as 别名]
# 或者: from website.project.model.MetaSchema import find [as 别名]
def test_metaschema_is_fine_with_same_name_but_different_version(self):
MetaSchema(name='foo', schema_version=1).save()
MetaSchema(name='foo', schema_version=2).save()
assert_equal(MetaSchema.find(name='foo').count(), 2)