(file, user)
return file
Checks if the file pushes user over their upload limit."
Checks if the file pushes user over their upload limit."
Checks if the file pushes user over their upload limit .
def check_upload_limit(file, user):
    """
    Checks if the file pushes user over their upload limit."
    """

    # Existing data.
    data = Data.objects.filter(owner=user, method=Data.UPLOAD)

    # The current cumulative size of the current data.
    current_size = data.aggregate(Sum("size"))["size__sum"] or 0

    # The projected size in MB.
    projected_size = file.size + current_size

    # Maximal cumulative sizes.
    max_size = user.profile.upload_size * 1024 * 1024

    # Current file size in MB
    file_mb = file.size / 1024 / 1024

    # Verify projected data sizes.
    if projected_size > max_size:
        msg = f"You don't have enough storage space for data of size <b>{file_mb:.2f} MB</b>"
        raise forms.ValidationError(mark_safe(msg))

    return file
def check_upload_limit ( file , user ) : # Existing data. data = Data . objects . filter ( owner = user , method = Data . UPLOAD ) # The current cumulative size of the current data. current_size = data . aggregate ( Sum ( "size" ) ) [ "size__sum" ] or 0 # The projected size in MB. projected_size = file . size + current_size # Maximal cumulative sizes. max_size = user . profile . upload_size * 1024 * 1024 # Current file size in MB file_mb = file . size / 1024 / 1024 # Verify projected data sizes. if projected_size > max_size : msg = f"You don't have enough storage space for data of size <b>{file_mb:.2f} MB</b>" raise forms . ValidationError ( mark_safe ( msg ) ) return file