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
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
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
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)