From e1f9d4ea365b73a8b1607d5bf4ce9ca131f066a3 Mon Sep 17 00:00:00 2001 From: "Jannis M. Hoffmann" Date: Wed, 12 Jun 2024 17:07:05 +0200 Subject: use jinja file size formatting and remove view.py --- src/jwebmail/__init__.py | 4 +-- src/jwebmail/templates/_folders.html | 2 +- src/jwebmail/templates/_main_table.html | 2 +- src/jwebmail/view.py | 46 --------------------------------- 4 files changed, 4 insertions(+), 50 deletions(-) delete mode 100644 src/jwebmail/view.py (limited to 'src/jwebmail') diff --git a/src/jwebmail/__init__.py b/src/jwebmail/__init__.py index 995fb0b..7a165e0 100644 --- a/src/jwebmail/__init__.py +++ b/src/jwebmail/__init__.py @@ -1,6 +1,7 @@ import os.path as os_path import pwd import sys +from datetime import datetime from os import environ from babel import parse_locale @@ -14,7 +15,6 @@ from werkzeug.middleware.proxy_fix import ProxyFix from .css import compile_css_command from .read_mails import load_user from .render_mail import format_mail -from .view import add_view_funcs from .webmail import ( about, displayheaders, @@ -81,7 +81,6 @@ def create_app(): login_manager.user_loader(load_user) login_manager.init_app(app) - add_view_funcs(app) route(app) @app.context_processor @@ -90,6 +89,7 @@ def create_app(): "version": __version__, "get_locale": get_locale, "format_mail": format_mail, + "parse_iso_date": datetime.fromisoformat, } @app.url_defaults diff --git a/src/jwebmail/templates/_folders.html b/src/jwebmail/templates/_folders.html index e9509e7..7b8f85d 100644 --- a/src/jwebmail/templates/_folders.html +++ b/src/jwebmail/templates/_folders.html @@ -44,7 +44,7 @@ {% if total_size %} {% trans %}mailbox size: {% endtrans %} - {{ total_size|byte_size10 }} + {{ total_size|filesizeformat }} {% endif %} diff --git a/src/jwebmail/templates/_main_table.html b/src/jwebmail/templates/_main_table.html index 700d77c..b6493fb 100644 --- a/src/jwebmail/templates/_main_table.html +++ b/src/jwebmail/templates/_main_table.html @@ -33,7 +33,7 @@
- {{ msg.byte_size|byte_size10 }} + {{ msg.byte_size|filesizeformat }}
diff --git a/src/jwebmail/view.py b/src/jwebmail/view.py deleted file mode 100644 index d435686..0000000 --- a/src/jwebmail/view.py +++ /dev/null @@ -1,46 +0,0 @@ -from datetime import datetime -from math import floor, log2, log10 - -from markupsafe import Markup - - -def print_sizes10(var): - i = floor(log10(var) / 3) - expo = i * 3 - - PREFIX = [ - "Byte", - "kByte", - "MByte", - "GByte", - "TByte", - "PByte", - ] - - return Markup(f"{round(var / (10**expo))} {PREFIX[i]}") - - -def print_sizes2(var): - i = floor(log2(var) / 10) - expo = i * 10 - - PREFIX = [ - "Byte", - "KiByte", - "MiByte", - "GiByte", - "TiByte", - "PiByte", - ] - - return Markup(f"{round(var / (2**expo))} {PREFIX[i]}") - - -def parse_iso_date(inp): - return datetime.fromisoformat(inp) - - -def add_view_funcs(app): - app.jinja_env.filters["byte_size2"] = print_sizes2 - app.jinja_env.filters["byte_size10"] = print_sizes10 - app.context_processor(lambda: dict(parse_iso_date=parse_iso_date)) -- cgit v1.2.3