Skip to content

Commit

Permalink
download:download_release_detail view: Display file sizes with huma…
Browse files Browse the repository at this point in the history
…n-readable units (#2354)

Make the release file sizes more readable by passing them through the
[filesizeformat filter][1].

[1]: https://docs.djangoproject.com/en/2.2/ref/templates/builtins/#filesizeformat
  • Loading branch information
noelleleigh committed Feb 21, 2024
1 parent bd3f080 commit c1b800b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions downloads/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def setUp(self):
is_source=True,
description='Gzipped source',
url='ftp/python/2.7.5/Python-2.7.5.tgz',
filesize=12345678,
)

self.draft_release = Release.objects.create(
Expand Down
3 changes: 3 additions & 0 deletions downloads/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def test_download_release_detail(self):
response = self.client.get(url)
self.assertEqual(response.status_code, 200)

with self.subTest("Release file sizes should be human-readable"):
self.assertInHTML("<td>11.8 MB</td>", response.content.decode())

url = reverse('download:download_release_detail', kwargs={'release_slug': 'fake_slug'})
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
Expand Down
2 changes: 1 addition & 1 deletion templates/downloads/release_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h1 class="page-title">Files</h1>
<td>{{ f.os.name }}</td>
<td>{{ f.description }}</td>
<td>{{ f.md5_sum }}</td>
<td>{{ f.filesize }}</td>
<td>{{ f.filesize|filesizeformat }}</td>
<td>{% if f.gpg_signature_file %}<a href="{{ f.gpg_signature_file }}">SIG</a>{% endif %}</td>
{% if release_files|has_sigstore_materials %}
{% if f.sigstore_bundle_file %}
Expand Down

0 comments on commit c1b800b

Please sign in to comment.