Skip to content

Commit da1c634

Browse files
albanbochslerfsbraunsourcery-ai[bot]
authored
fix: Avoid locale-dependent ratio (#1536)
* fix: Avoid locale-dependent ratio * Update filer/templatetags/filer_admin_tags.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> * Add test for locale-independent sidebar image ratio formatting * Use lowercase formatting * Update GitHub Actions to use latest Ubuntu version * Update furo package version in requirements.txt --------- Co-authored-by: Fabian Braun <[email protected]> Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
1 parent 55a0e70 commit da1c634

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

.github/workflows/frontend.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on: [push]
44

55
jobs:
66
gulp:
7-
runs-on: ubuntu-20.04
7+
runs-on: ubuntu-latest
88
strategy:
99
matrix:
1010
node-version: [16.20.x]

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ docutils==0.17.1
3030
# via
3131
# restructuredtext-lint
3232
# sphinx
33-
furo==2021.6.24b37
33+
furo==2025.7.19
3434
# via -r requirements.in
3535
idna==3.3
3636
# via requests

filer/templatetags/filer_admin_tags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def get_aspect_ratio_and_download_url(context, detail, file, height, width):
190190
# because they don't really have width or height
191191
if file.width:
192192
width, height = 210, ceil(210 / file.width * file.height)
193-
context['sidebar_image_ratio'] = file.width / 210
193+
context['sidebar_image_ratio'] = '%.6f' % (file.width / 210)
194194
return height, width, context
195195

196196

tests/test_admin.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,6 +1935,22 @@ def test_file_icon_with_size(self):
19351935
self.assertNotIn('sidebar_image_ratio', context.keys())
19361936
self.assertIn('download_url', context.keys())
19371937

1938+
def test_sidebar_image_ratio_format(self):
1939+
"""
1940+
Test that sidebar_image_ratio is formatted as a string with 6 decimal places
1941+
to ensure consistent formatting regardless of locale settings
1942+
"""
1943+
image = Image.objects.create(name='test.jpg')
1944+
image._width = 100
1945+
image._height = 200
1946+
image.save()
1947+
context = {}
1948+
height, width, context = get_aspect_ratio_and_download_url(context=context, detail=True, file=image, height=40, width=40)
1949+
self.assertIsInstance(context['sidebar_image_ratio'], str)
1950+
expected_ratio = '%.6f' % (image.width / 210)
1951+
self.assertEqual(context['sidebar_image_ratio'], expected_ratio)
1952+
self.assertEqual(context['sidebar_image_ratio'], '0.476190')
1953+
19381954

19391955
class AdditionalAdminFormsTests(TestCase):
19401956
def setUp(self):

0 commit comments

Comments
 (0)