mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-22 01:21:07 +00:00
Simplify logic for rendering user exports
This commit is contained in:
parent
a51402241b
commit
f721289b1d
2 changed files with 11 additions and 21 deletions
|
@ -123,7 +123,9 @@
|
|||
</span>
|
||||
</td>
|
||||
<td>
|
||||
{% if export.size %}
|
||||
<span>{{ export.size|get_file_size }}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if export.url %}
|
||||
|
@ -133,7 +135,7 @@
|
|||
{% trans "Download your export" %}
|
||||
</span>
|
||||
</a>
|
||||
{% elif export.job.complete and not export.job.status == "stopped" and not export.job.status == "failed" %}
|
||||
{% elif export.unavailable %}
|
||||
{% trans "Archive is no longer available" %}
|
||||
{% endif %}
|
||||
</td>
|
||||
|
|
|
@ -165,28 +165,16 @@ class ExportUser(View):
|
|||
for job in jobs:
|
||||
export = {"job": job}
|
||||
|
||||
if settings.USE_S3:
|
||||
storage = S3Boto3Storage(querystring_auth=True, custom_domain=None)
|
||||
|
||||
# for s3 we create a new tar file in s3,
|
||||
# so we need to check the size of _that_ file
|
||||
if job.export_data:
|
||||
try:
|
||||
export["size"] = S3Boto3Storage.size(
|
||||
storage, f"exports/{job.task_id}.tar.gz"
|
||||
)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
export["size"] = 0
|
||||
|
||||
else:
|
||||
# for local storage export_data is the tar file
|
||||
try:
|
||||
export["size"] = job.export_data.size if job.export_data else 0
|
||||
export["size"] = job.export_data.size
|
||||
export["url"] = reverse("prefs-export-file", args=[job.task_id])
|
||||
except FileNotFoundError:
|
||||
# file no longer exists
|
||||
export["size"] = 0
|
||||
|
||||
if export["size"] > 0:
|
||||
export["url"] = reverse("prefs-export-file", args=[job.task_id])
|
||||
# file no longer exists locally
|
||||
export["unavailable"] = True
|
||||
except Exception: # pylint: disable=broad-except
|
||||
# file no longer exists on storage backend
|
||||
export["unavailable"] = True
|
||||
|
||||
exports.append(export)
|
||||
|
||||
|
|
Loading…
Reference in a new issue