Skip to content

Commit 69b1ad2

Browse files
committed
add fields for alt text in all languages
1 parent af86098 commit 69b1ad2

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

finder/browser/views.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,10 @@ def crop(self, request, image_id):
266266
cropped_image_path = image.get_cropped_path(width, height)
267267
if not default_storage.exists(cropped_image_path):
268268
image.crop(cropped_image_path, width, height)
269-
cropped_image_url = default_storage.url(cropped_image_path)
270269
return {
271270
'image_id': image_id,
272-
'alt_text': image.meta_data.get('alt_text', image.name),
273-
'cropped_image_url': cropped_image_url,
271+
'cropped_image_url': default_storage.url(cropped_image_path),
274272
'width': width,
275273
'height': height,
274+
'meta_data': image.get_meta_data(),
276275
}

finder/contrib/image/models.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pathlib import Path
22

3+
from django.conf import settings
34
from django.contrib.staticfiles.storage import staticfiles_storage
45
from django.db import models
56
from django.utils.functional import cached_property
@@ -56,8 +57,14 @@ def get_cropped_path(self, width, height):
5657
)
5758

5859
def get_meta_data(self):
59-
return {
60+
alt_text = self.meta_data.get('alt_text', self.name)
61+
data = {
6062
'orig_width': self.width,
6163
'orig_height': self.height,
62-
'alt_text': self.meta_data.get('alt_text', self.name),
64+
'alt_text': alt_text,
6365
}
66+
for code, language in settings.LANGUAGES:
67+
if code != settings.LANGUAGE_CODE:
68+
key = f'alt_text_{code}'
69+
data[key] = self.meta_data.get(key, alt_text)
70+
return data

0 commit comments

Comments
 (0)