Skip to content

Commit c1b800b

Browse files
authored
download:download_release_detail view: Display file sizes with human-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
1 parent bd3f080 commit c1b800b

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

downloads/tests/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def setUp(self):
6464
is_source=True,
6565
description='Gzipped source',
6666
url='ftp/python/2.7.5/Python-2.7.5.tgz',
67+
filesize=12345678,
6768
)
6869

6970
self.draft_release = Release.objects.create(

downloads/tests/test_views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ def test_download_release_detail(self):
4040
response = self.client.get(url)
4141
self.assertEqual(response.status_code, 200)
4242

43+
with self.subTest("Release file sizes should be human-readable"):
44+
self.assertInHTML("<td>11.8 MB</td>", response.content.decode())
45+
4346
url = reverse('download:download_release_detail', kwargs={'release_slug': 'fake_slug'})
4447
response = self.client.get(url)
4548
self.assertEqual(response.status_code, 404)

templates/downloads/release_detail.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ <h1 class="page-title">Files</h1>
6666
<td>{{ f.os.name }}</td>
6767
<td>{{ f.description }}</td>
6868
<td>{{ f.md5_sum }}</td>
69-
<td>{{ f.filesize }}</td>
69+
<td>{{ f.filesize|filesizeformat }}</td>
7070
<td>{% if f.gpg_signature_file %}<a href="{{ f.gpg_signature_file }}">SIG</a>{% endif %}</td>
7171
{% if release_files|has_sigstore_materials %}
7272
{% if f.sigstore_bundle_file %}

0 commit comments

Comments
 (0)