Merge pull request #3089 from bookwyrm-social/notification-and-download-links

UI changes for notification and download link in import/export flow
This commit is contained in:
Mouse Reeve 2023-11-06 16:31:09 -08:00 committed by GitHub
commit 9ddd631549
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 13 deletions

View file

@ -1,11 +1,15 @@
{% extends 'notifications/items/layout.html' %}
{% load i18n %}
{% block primary_link %}{% spaceless %}
{% url 'prefs-user-export' %}
{% endspaceless %}{% endblock %}
{% block icon %}
<span class="icon icon-list"></span>
{% endblock %}
{% block description %}
{% url 'prefs-export-file' notification.related_user_export.task_id as url %}
{% blocktrans %}Your <a download href="{{ url }}">user export</a> is ready.{% endblocktrans %}
{% url 'prefs-user-export' as url %}
{% blocktrans %}Your <a href="{{ url }}">user export</a> is ready.{% endblocktrans %}
{% endblock %}

View file

@ -1,6 +1,10 @@
{% extends 'notifications/items/layout.html' %}
{% load i18n %}
{% block primary_link %}{% spaceless %}
{% url 'user-import' %}
{% endspaceless %}{% endblock %}
{% block icon %}
<span class="icon icon-list"></span>
{% endblock %}

View file

@ -1,5 +1,6 @@
{% extends 'preferences/layout.html' %}
{% load i18n %}
{% load utilities %}
{% block title %}{% trans "User Export" %}{% endblock %}
@ -38,14 +39,14 @@
<table class="table is-striped is-fullwidth">
<tr>
<th>
{% trans "Date Created" %}
</th>
<th>
{% trans "Last Updated" %}
{% trans "Date" %}
</th>
<th>
{% trans "Status" %}
</th>
<th colspan="2">
{% trans "Size" %}
</th>
</tr>
{% if not jobs %}
<tr>
@ -56,13 +57,6 @@
{% endif %}
{% for job in jobs %}
<tr>
<td>
{% if job.complete and not job.status == "stopped" and not job.status == "failed" %}
<p><a download="" href="/preferences/user-export/{{ job.task_id }}">{{ job.created_date }}</a></p>
{% else %}
<p>{{ job.created_date }}</p>
{% endif %}
</td>
<td>{{ job.updated_date }}</td>
<td>
<span
@ -86,6 +80,21 @@
{% 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>
<a download="" href="/preferences/user-export/{{ job.task_id }}">
<span class="icon icon-download" aria-hidden="true"></span>
<span class="is-hidden-mobile">
{% trans "Download your export" %}
</span>
</a>
</p>
{% endif %}
</td>
</tr>
{% endfor %}
</table>

View file

@ -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 ""