diff --git a/bookwyrm/templates/notifications/items/user_export.html b/bookwyrm/templates/notifications/items/user_export.html index d4ab04faa..1df40dbac 100644 --- a/bookwyrm/templates/notifications/items/user_export.html +++ b/bookwyrm/templates/notifications/items/user_export.html @@ -11,5 +11,5 @@ {% block description %} {% url 'prefs-user-export' as url %} - {% blocktrans %}Your user export is ready.{% endblocktrans %} + {% blocktrans %}Your user export is ready.{% endblocktrans %} {% endblock %} diff --git a/bookwyrm/templates/preferences/export-user.html b/bookwyrm/templates/preferences/export-user.html index 0a45b8b0a..da8f537a6 100644 --- a/bookwyrm/templates/preferences/export-user.html +++ b/bookwyrm/templates/preferences/export-user.html @@ -1,5 +1,6 @@ {% extends 'preferences/layout.html' %} {% load i18n %} +{% load utilities %} {% block title %}{% trans "User Export" %}{% endblock %} @@ -40,9 +41,12 @@ {% trans "Date" %} - + {% trans "Status" %} + + {% trans "Size" %} + {% if not jobs %} @@ -76,6 +80,9 @@ {% endif %} + + {{ job.export_data|get_file_size }} + {% if job.complete and not job.status == "stopped" and not job.status == "failed" %}

diff --git a/bookwyrm/templatetags/utilities.py b/bookwyrm/templatetags/utilities.py index 42e67990f..3ae14c17c 100644 --- a/bookwyrm/templatetags/utilities.py +++ b/bookwyrm/templatetags/utilities.py @@ -125,3 +125,20 @@ def id_to_username(user_id): value = f"{name}@{domain}" return value + + +@register.filter(name="get_file_size") +def get_file_size(file): + """display the size of a file in human readable terms""" + + try: + raw_size = os.stat(file.path).st_size + if raw_size < 1024: + return f"{raw_size} bytes" + if raw_size < 1024**2: + return f"{raw_size/1024:.2f} KB" + if raw_size < 1024**3: + return f"{raw_size/1024**2:.2f} MB" + return f"{raw_size/1024**3:.2f} GB" + except Exception: # pylint: disable=broad-except + return ""