Пример #1
0
def get_all_alloc(request):
    """Get all allocations, grouped by project.

    Args:
        request: the request that is passed in.

    Raises:
        Exception: when loading projects fails.

    Returns:
        json: dumps all data as serialized json.
    """
    try:
        keycloak_client = KeycloakClient()
        user_attributes = keycloak_client.get_all_users_attributes()
        mapper = ProjectAllocationMapper(request)
        resp = mapper.get_all_projects()
        logger.debug("Total projects: %s", len(resp))
        for r in resp:
            pi_attributes = user_attributes.get(r["pi"]["username"], {})
            if pi_attributes:
                institution = pi_attributes.get("affiliationInstitution", [])
                country = pi_attributes.get("country", [])
                r["pi"]["institution"] = next(iter(institution), None)
                r["pi"]["country"] = next(iter(country), None)
    except Exception as e:
        logger.exception("Error loading chameleon projects")
        messages.error(request, e)
        raise
    return json.dumps(resp)
Пример #2
0
def get_all_alloc(request):
    """Get all allocations, grouped by project.

    Args:
        request: the request that is passed in.

    Raises:
        Exception: when loading projects fails.

    Returns:
        json: dumps all data as serialized json.
    """
    try:
        mapper = ProjectAllocationMapper(request)
        resp = mapper.get_all_projects()
        logger.debug("Total projects: %s", len(resp))
    except Exception as e:
        logger.exception("Error loading chameleon projects")
        messages.error(request, e)
        raise
    return json.dumps(resp)