Beispiel #1
0
async def users_list(
    response: Response,
    db=Depends(get_db),
    current_user=Depends(get_current_active_user),
):
    """
    Get all users with usage
    """
    users = jsonable_encoder(get_users_with_ports_usage(db))
    # This is necessary for react-admin to work
    response.headers["Content-Range"] = f"0-9/{len(users)}"
    users_with_usage = []
    for user in users:
        user["download_usage"] = 0
        user["upload_usage"] = 0
        for port in user.get("allowed_ports", []):
            if port["port"]["usage"]:
                user["download_usage"] += port["port"]["usage"].get(
                    "download", 0
                )
                user["upload_usage"] += port["port"]["usage"].get("upload", 0)
        user["readable_download_usage"] = get_readable_size(
            user["download_usage"]+user["upload_usage"]
        )
        user["readable_upload_usage"] = get_readable_size(user["upload_usage"]+user["download_usage"])
        users_with_usage.append(user)
    return users_with_usage
Beispiel #2
0
 def default_readable_upload(cls, v, *, values, **kwargs):
     return v or get_readable_size(values["upload"] + values["download"])
Beispiel #3
0
 def default_readable_upload(cls, v, *, values, **kwargs):
     return v or get_readable_size(values['upload'])