diff options
author | Jannis M. Hoffmann <jannis@fehcom.de> | 2024-06-12 17:07:05 +0200 |
---|---|---|
committer | Jannis M. Hoffmann <jannis@fehcom.de> | 2024-06-12 17:07:05 +0200 |
commit | e1f9d4ea365b73a8b1607d5bf4ce9ca131f066a3 (patch) | |
tree | 294d72b71e65f8c321f953095515b974a2c71856 | |
parent | 3a69fc47718d6c366b1ba1e797eb6c0d7036c129 (diff) |
use jinja file size formatting and remove view.py
-rw-r--r-- | src/jwebmail/__init__.py | 4 | ||||
-rw-r--r-- | src/jwebmail/templates/_folders.html | 2 | ||||
-rw-r--r-- | src/jwebmail/templates/_main_table.html | 2 | ||||
-rw-r--r-- | src/jwebmail/view.py | 46 |
4 files changed, 4 insertions, 50 deletions
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 @@ <span class="column has-text-centered"> {% if total_size %} {% trans %}mailbox size: {% endtrans %} - {{ total_size|byte_size10 }} + {{ total_size|filesizeformat }} {% endif %} </span> </div> 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 @@ </div> <div class="column is-2"> - {{ msg.byte_size|byte_size10 }} + {{ msg.byte_size|filesizeformat }} </div> </div> </div> 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)) |