Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Human readable file size message in validator #421

Open
MrTango opened this issue Nov 24, 2023 · 1 comment
Open

Human readable file size message in validator #421

MrTango opened this issue Nov 24, 2023 · 1 comment

Comments

@MrTango
Copy link
Contributor

MrTango commented Nov 24, 2023

The file validator should return some like this:
The uploaded file is larger than 15.0 MiB!
instead of this:
The uploaded file is larger than 15728640 Bytes!

we could implement a conversion like this:

def sizeof_fmt(num, suffix="B"):
    for unit in ("", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"):
        if abs(num) < 1024.0:
            return f"{num:3.1f} {unit}{suffix}"
        num /= 1024.0
    return f"{num:.1f} Yi{suffix}"

hsize = sizeof_fmt(size)

and use this in the message show to the user.

@davisagli
Copy link
Member

Use https://github.com/plone/plone.base/blob/main/src/plone/base/utils.py#L40 rather than writing another one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants