How to use the codalab.lib.server_util.json_api_include function in codalab

To help you get started, we’ve selected a few codalab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github codalab / codalab-worksheets / codalab / rest / bundles.py View on Github external
owner_ids = set(b['owner_id'] for b in bundles if b['owner_id'] is not None)
        json_api_include(document, UserSchema(), local.model.get_users(owner_ids))

    if 'group_permissions' in include_set:
        for bundle in bundles:
            json_api_include(
                document, BundlePermissionSchema(), bundle.get('group_permissions', [])
            )

    if 'children' in include_set:
        for bundle in bundles:
            json_api_include(document, BundleSchema(), bundle.get('children', []))

    if 'host_worksheets' in include_set:
        for bundle in bundles:
            json_api_include(document, WorksheetSchema(), bundle.get('host_worksheets', []))

    return document
github codalab / codalab-worksheets / codalab / rest / groups.py View on Github external
def include_group_relationships(document, groups):
    user_ids = set()
    for group in groups:
        user_ids.add(group['owner_id'])
        user_ids.update(group['members'])
        user_ids.update(group['admins'])
    json_api_include(document, UserSchema(), local.model.get_users(user_ids))
github codalab / codalab-worksheets / codalab / rest / worksheets.py View on Github external
'items.bundle.owner',
            'items.subworksheet',
        }
    )
    worksheet = get_worksheet_info(
        uuid,
        fetch_items='items' in include_set,
        fetch_permissions='group_permissions' in include_set,
    )

    # Build response document
    document = WorksheetSchema().dump(worksheet).data

    # Include items
    if 'items' in include_set:
        json_api_include(document, WorksheetItemSchema(), worksheet['items'])

    user_ids = set()

    # Include bundles
    if 'items.bundle' in include_set:
        bundle_uuids = {
            item['bundle_uuid']
            for item in worksheet['items']
            if item['type'] == worksheet_util.TYPE_BUNDLE and item['bundle_uuid'] is not None
        }
        bundle_infos = list(get_bundle_infos(bundle_uuids).values())
        json_api_include(document, BundleSchema(), bundle_infos)
        if 'items.bundle.owner' in include_set:
            user_ids.update({b['owner_id'] for b in bundle_infos})

    # Include users
github codalab / codalab-worksheets / codalab / rest / bundles.py View on Github external
owner_ids = set(b['owner_id'] for b in bundles if b['owner_id'] is not None)
        json_api_include(document, UserSchema(), local.model.get_users(owner_ids))

    if 'group_permissions' in include_set:
        for bundle in bundles:
            json_api_include(
                document, BundlePermissionSchema(), bundle.get('group_permissions', [])
            )

    if 'children' in include_set:
        for bundle in bundles:
            json_api_include(document, BundleSchema(), bundle.get('children', []))

    if 'host_worksheets' in include_set:
        for bundle in bundles:
            json_api_include(document, WorksheetSchema(), bundle.get('host_worksheets', []))

    return document
github codalab / codalab-worksheets / codalab / rest / worksheets.py View on Github external
# Include items
    if 'items' in include_set:
        json_api_include(document, WorksheetItemSchema(), worksheet['items'])

    user_ids = set()

    # Include bundles
    if 'items.bundle' in include_set:
        bundle_uuids = {
            item['bundle_uuid']
            for item in worksheet['items']
            if item['type'] == worksheet_util.TYPE_BUNDLE and item['bundle_uuid'] is not None
        }
        bundle_infos = list(get_bundle_infos(bundle_uuids).values())
        json_api_include(document, BundleSchema(), bundle_infos)
        if 'items.bundle.owner' in include_set:
            user_ids.update({b['owner_id'] for b in bundle_infos})

    # Include users
    if 'owner' in include_set:
        user_ids.add(worksheet['owner_id'])
    if user_ids:
        json_api_include(document, UserSchema(), local.model.get_users(user_ids))

    # Include subworksheets
    if 'items.subworksheets' in include_set:
        subworksheet_uuids = {
            item['subworksheet_uuid']
            for item in worksheet['items']
            if item['type'] == worksheet_util.TYPE_WORKSHEET
            and item['subworksheet_uuid'] is not None
github codalab / codalab-worksheets / codalab / rest / bundles.py View on Github external
if query_get_bool('include_display_metadata', default=False):
        for bundle, data in zip(bundles, document['data']):
            bundle_class = get_bundle_subclass(bundle['bundle_type'])
            json_api_meta(
                data,
                {
                    'editable_metadata_keys': worksheet_util.get_editable_metadata_fields(
                        bundle_class
                    ),
                    'metadata_type': worksheet_util.get_metadata_types(bundle_class),
                },
            )

    if 'owner' in include_set:
        owner_ids = set(b['owner_id'] for b in bundles if b['owner_id'] is not None)
        json_api_include(document, UserSchema(), local.model.get_users(owner_ids))

    if 'group_permissions' in include_set:
        for bundle in bundles:
            json_api_include(
                document, BundlePermissionSchema(), bundle.get('group_permissions', [])
            )

    if 'children' in include_set:
        for bundle in bundles:
            json_api_include(document, BundleSchema(), bundle.get('children', []))

    if 'host_worksheets' in include_set:
        for bundle in bundles:
            json_api_include(document, WorksheetSchema(), bundle.get('host_worksheets', []))

    return document
github codalab / codalab-worksheets / codalab / rest / bundles.py View on Github external
},
            )

    if 'owner' in include_set:
        owner_ids = set(b['owner_id'] for b in bundles if b['owner_id'] is not None)
        json_api_include(document, UserSchema(), local.model.get_users(owner_ids))

    if 'group_permissions' in include_set:
        for bundle in bundles:
            json_api_include(
                document, BundlePermissionSchema(), bundle.get('group_permissions', [])
            )

    if 'children' in include_set:
        for bundle in bundles:
            json_api_include(document, BundleSchema(), bundle.get('children', []))

    if 'host_worksheets' in include_set:
        for bundle in bundles:
            json_api_include(document, WorksheetSchema(), bundle.get('host_worksheets', []))

    return document
github codalab / codalab-worksheets / codalab / rest / bundles.py View on Github external
},
            )

    if 'owner' in include_set:
        owner_ids = set(b['owner_id'] for b in bundles if b['owner_id'] is not None)
        json_api_include(document, UserSchema(), local.model.get_users(owner_ids))

    if 'group_permissions' in include_set:
        for bundle in bundles:
            json_api_include(
                document, BundlePermissionSchema(), bundle.get('group_permissions', [])
            )

    if 'children' in include_set:
        for bundle in bundles:
            json_api_include(document, BundleSchema(), bundle.get('children', []))

    if 'host_worksheets' in include_set:
        for bundle in bundles:
            json_api_include(document, WorksheetSchema(), bundle.get('host_worksheets', []))

    return document