예제 #1
0
파일: drafts.py 프로젝트: adlius/osf.io
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_schemas = []
    if include == 'latest':
        schema_names = list(MetaSchema.objects.all().values_list('name', flat=True).distinct())
        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.active
    ]
    meta_schemas.sort(key=lambda a: METASCHEMA_ORDERING.index(a.name))
    return {
        'meta_schemas': [
            serialize_meta_schema(ms) for ms in meta_schemas[:count]
        ]
    }, http.OK
예제 #2
0
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_schemas = []
    if include == 'latest':
        schema_names = list(MetaSchema.objects.all().values_list('name', flat=True).distinct())
        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.active
    ]
    meta_schemas.sort(key=lambda a: METASCHEMA_ORDERING.index(a.name))
    return {
        'meta_schemas': [
            serialize_meta_schema(ms) for ms in meta_schemas[:count]
        ]
    }, http.OK
예제 #3
0
파일: drafts.py 프로젝트: futa-ikeda/osf.io
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_schemas = RegistrationSchema.objects.filter(active=True)
    if include == 'latest':
        meta_schemas.filter(schema_version=LATEST_SCHEMA_VERSION)

    meta_schemas = sorted(meta_schemas,
                          key=lambda x: METASCHEMA_ORDERING.index(x.name))

    return {
        'meta_schemas':
        [serialize_meta_schema(ms) for ms in meta_schemas[:count]]
    }, http.OK
예제 #4
0
파일: drafts.py 프로젝트: mfraezz/osf.io
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_schemas = MetaSchema.objects.filter(active=True)
    if include == 'latest':
        meta_schemas.filter(schema_version=LATEST_SCHEMA_VERSION)

    meta_schemas = sorted(meta_schemas, key=lambda x: METASCHEMA_ORDERING.index(x.name))

    return {
        'meta_schemas': [
            serialize_meta_schema(ms) for ms in meta_schemas[:count]
        ]
    }, http.OK
예제 #5
0
def order_schemas(schema):
    """ Schemas not specified in METASCHEMA_ORDERING get sent to the bottom of the list."""
    try:
        return METASCHEMA_ORDERING.index(schema.name)
    except ValueError:
        return len(METASCHEMA_ORDERING)