mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-25 11:01:12 +00:00
Merge pull request #3091 from hughrun/notification-and-download-links
show filesize on user downloads page
This commit is contained in:
commit
1b958a9b31
3 changed files with 26 additions and 2 deletions
|
@ -11,5 +11,5 @@
|
|||
|
||||
{% block description %}
|
||||
{% url 'prefs-user-export' as url %}
|
||||
{% blocktrans %}Your <a download href="{{ url }}">user export</a> is ready.{% endblocktrans %}
|
||||
{% blocktrans %}Your <a href="{{ url }}">user export</a> is ready.{% endblocktrans %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{% extends 'preferences/layout.html' %}
|
||||
{% load i18n %}
|
||||
{% load utilities %}
|
||||
|
||||
{% block title %}{% trans "User Export" %}{% endblock %}
|
||||
|
||||
|
@ -40,9 +41,12 @@
|
|||
<th>
|
||||
{% trans "Date" %}
|
||||
</th>
|
||||
<th colspan="2">
|
||||
<th>
|
||||
{% trans "Status" %}
|
||||
</th>
|
||||
<th colspan="2">
|
||||
{% trans "Size" %}
|
||||
</th>
|
||||
</tr>
|
||||
{% if not jobs %}
|
||||
<tr>
|
||||
|
@ -76,6 +80,9 @@
|
|||
{% endif %}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<span>{{ job.export_data|get_file_size }}</span>
|
||||
</td>
|
||||
<td>
|
||||
{% if job.complete and not job.status == "stopped" and not job.status == "failed" %}
|
||||
<p>
|
||||
|
|
|
@ -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 ""
|
||||
|
|
Loading…
Reference in a new issue