added a jinja helper function for displaying file sizes
This commit is contained in:
parent
bf9573ba60
commit
edb19bde80
@ -41,4 +41,18 @@ def create_app():
|
||||
app.config['SQLALCHEMY_RECORD_QUERIES'] = os.getenv("SQLALCHEMY_RECORD_QUERIES")
|
||||
print(f"Current Environment: " + app.config['ENVIRONMENT'])
|
||||
|
||||
# register helper function
|
||||
app.jinja_env.globals.update(sizeof_fmt=sizeof_fmt)
|
||||
|
||||
return app
|
||||
|
||||
|
||||
# helper function to print formatted file size from https://stackoverflow.com/a/1094933
|
||||
def sizeof_fmt(num, suffix="B"):
|
||||
if type(num) == "String":
|
||||
num = int(num)
|
||||
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}"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user