From aa30ffaf77c9e680d0070af0bc8f52c94ecb0bb6 Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Sun, 9 Nov 2025 11:52:18 +0100 Subject: [PATCH 1/5] feature: add download of alt-texts --- src/download.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/download.py b/src/download.py index 4c9d586..fbabf7e 100644 --- a/src/download.py +++ b/src/download.py @@ -106,6 +106,11 @@ class Download: with (self.config.p_data_pictures / f"{picture['id']}include.tex").open("w") as file: file.write(picture["latex"]) + # Save Alt-Text to file + if picture["alt_text_reviewed"] is not None: + with (self.config.p_data_pictures / f"{picture['id']}.txt").open("w") as file: + file.write(picture["alt_text"]) + # Download SVG data = self.api.get_file(f"assets/{picture['picture']}") with (self.config.p_data_pictures / f"{picture['id']}.svg").open("wb") as file: From f5e5c93ad36c9a88ed8bb83bbd54df7ec491c371 Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Sun, 9 Nov 2025 13:02:46 +0100 Subject: [PATCH 2/5] feature: add alt-text support for pictures --- renderer/fifty_ohm_html_renderer.py | 12 ++++++++---- src/build.py | 24 +++++++++++++++++++----- src/download.py | 7 +++++-- templates/html/question.html | 4 ++-- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/renderer/fifty_ohm_html_renderer.py b/renderer/fifty_ohm_html_renderer.py index 9e00d84..bdf0d54 100644 --- a/renderer/fifty_ohm_html_renderer.py +++ b/renderer/fifty_ohm_html_renderer.py @@ -190,18 +190,22 @@ class FiftyOhmHtmlRenderer(HtmlRenderer): return base.join(filter(lambda x: x is not None, [self.render(child) for child in token.children])) @staticmethod - def render_picture_helper(id, ref, text, number): + def render_picture_helper(id, ref, text, number, alt_text): return f"""
- + {alt_text}
Abbildung {number}: {text}
""" def render_picture(self, token): if self.picture_handler is not None: - self.picture_handler(token.id) - return self.render_picture_helper(token.id, token.ref, token.text, token.number) + alt_text = self.picture_handler(token.id) + + if alt_text is None: + alt_text = "Alt-Text noch nicht verfügbar" + + return self.render_picture_helper(token.id, token.ref, token.text, token.number, alt_text) @staticmethod def render_photo_helper(id, ref, text, number): diff --git a/src/build.py b/src/build.py index de00c10..0f89135 100644 --- a/src/build.py +++ b/src/build.py @@ -80,10 +80,10 @@ class Build: answers = [] if metadata["picture_a"] != "": - self.__picture_handler(metadata["picture_a"]) - self.__picture_handler(metadata["picture_b"]) - self.__picture_handler(metadata["picture_c"]) - self.__picture_handler(metadata["picture_d"]) + alt_text_a = self.__picture_handler(metadata["picture_a"]) + alt_text_b = self.__picture_handler(metadata["picture_b"]) + alt_text_c = self.__picture_handler(metadata["picture_c"]) + alt_text_d = self.__picture_handler(metadata["picture_d"]) answer_pictures = [ metadata["picture_a"], @@ -91,14 +91,24 @@ class Build: metadata["picture_c"], metadata["picture_d"], ] + + alt_text_answers = [ + alt_text_a, + alt_text_b, + alt_text_c, + alt_text_d, + ] + else: answer_pictures = [] + alt_text_answers = [] if "picture_question" in question and metadata["picture_question"] != "": picture_question = metadata["picture_question"] - self.__picture_handler(picture_question) + alt_text_question = self.__picture_handler(picture_question) else: picture_question = "" + alt_text_question = "" return question_template.render( question=question["question"], @@ -107,6 +117,8 @@ class Build: picture_question=picture_question, answers=answers, answer_pictures=answer_pictures, + alt_text_answers=alt_text_answers, + alt_text_question=alt_text_question, ) def __build_question_slide(self, input): @@ -122,6 +134,8 @@ class Build: file = f"{id}.svg" try: shutil.copyfile(self.config.p_data_pictures / file, self.config.p_build_pictures / file) + if (self.config.p_data_pictures / f"{id}.txt").exists(): + return (self.config.p_data_pictures / f"{id}.txt").read_text() except FileNotFoundError: tqdm.write(f"\033[31mPicture #{id} not found\033[0m") diff --git a/src/download.py b/src/download.py index fbabf7e..684fdd7 100644 --- a/src/download.py +++ b/src/download.py @@ -107,9 +107,12 @@ class Download: file.write(picture["latex"]) # Save Alt-Text to file - if picture["alt_text_reviewed"] is not None: + prefix = "" + if picture["alt_text"] is not None: + if picture["alt_text_reviewed"] is None: + prefix = "Der folgende Alt-Text wurde noch nicht geprüft: " with (self.config.p_data_pictures / f"{picture['id']}.txt").open("w") as file: - file.write(picture["alt_text"]) + file.write(prefix + picture["alt_text"]) # Download SVG data = self.api.get_file(f"assets/{picture['picture']}") diff --git a/templates/html/question.html b/templates/html/question.html index 68c4923..a95851c 100644 --- a/templates/html/question.html +++ b/templates/html/question.html @@ -1,7 +1,7 @@
{{ number }}: {{ question }}
{% if picture_question %} -
+
{{ alt_text_question }}
{% endif %}
{% for i in range(4) %} @@ -10,7 +10,7 @@ {{ answers[i] }} {% endif %} {% if answer_pictures[i] %} -
+
{{ alt_text_answers[i] }}
{% endif %} {% if i == 0 %}
check
From f00f0481a99322292060c56e1d12984eb2db498d Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Sun, 9 Nov 2025 15:42:13 +0100 Subject: [PATCH 3/5] fix: tests for pictures --- renderer/fifty_ohm_html_renderer.py | 6 ++---- test/test_picture.py | 6 ++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/renderer/fifty_ohm_html_renderer.py b/renderer/fifty_ohm_html_renderer.py index bdf0d54..8743ed6 100644 --- a/renderer/fifty_ohm_html_renderer.py +++ b/renderer/fifty_ohm_html_renderer.py @@ -199,11 +199,9 @@ class FiftyOhmHtmlRenderer(HtmlRenderer): """ def render_picture(self, token): + alt_text = "Alt-Text noch nicht verfügbar" if self.picture_handler is not None: - alt_text = self.picture_handler(token.id) - - if alt_text is None: - alt_text = "Alt-Text noch nicht verfügbar" + alt_text = self.picture_handler(token.id) or alt_text return self.render_picture_helper(token.id, token.ref, token.text, token.number, alt_text) diff --git a/test/test_picture.py b/test/test_picture.py index 23aef01..ea1eced 100644 --- a/test/test_picture.py +++ b/test/test_picture.py @@ -9,7 +9,9 @@ from test.util import paragraph @pytest.mark.html def test_picture_html(): assertions = { - "[picture:123:abc:Text]": FiftyOhmHtmlRenderer.render_picture_helper("123", "abc", "Text", "TODO"), + "[picture:0:abc:Text]": FiftyOhmHtmlRenderer.render_picture_helper( + "0", "abc", "Text", "TODO", "Alt-Text noch nicht verfügbar" + ), } for assertion in assertions: @@ -19,7 +21,7 @@ def test_picture_html(): @pytest.mark.latex def test_picture_latex(): assertions = { - "[picture:123:abc:Text]": FiftyOhmLaTeXRenderer.render_picture_helper("123", "abc", "Text", "TODO"), + "[picture:0:abc:Text]": FiftyOhmLaTeXRenderer.render_picture_helper("0", "abc", "Text", "TODO"), } for assertion in assertions: From ee5197000e9b5cf76ca0ced2b8a107af61c0d5b9 Mon Sep 17 00:00:00 2001 From: Matthias Jung Date: Sun, 9 Nov 2025 17:48:47 +0100 Subject: [PATCH 4/5] feature: alt-text for photos --- renderer/fifty_ohm_html_renderer.py | 9 +++++---- src/build.py | 2 ++ src/download.py | 9 +++++++++ test/test_photo.py | 4 +++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/renderer/fifty_ohm_html_renderer.py b/renderer/fifty_ohm_html_renderer.py index 8743ed6..e50bcac 100644 --- a/renderer/fifty_ohm_html_renderer.py +++ b/renderer/fifty_ohm_html_renderer.py @@ -206,18 +206,19 @@ class FiftyOhmHtmlRenderer(HtmlRenderer): return self.render_picture_helper(token.id, token.ref, token.text, token.number, alt_text) @staticmethod - def render_photo_helper(id, ref, text, number): + def render_photo_helper(id, ref, text, number, alt_text): return f"""
- + {alt_text}
Abbildung {number}: {text}
""" def render_photo(self, token): + alt_text = "Alt-Text noch nicht verfügbar" if self.photo_handler is not None: - self.photo_handler(token.id) - return self.render_photo_helper(token.id, token.ref, token.text, token.number) + alt_text = self.photo_handler(token.id) or alt_text + return self.render_photo_helper(token.id, token.ref, token.text, token.number, alt_text) @staticmethod def render_cell_helper(cell, alignment, type): diff --git a/src/build.py b/src/build.py index 0f89135..0729531 100644 --- a/src/build.py +++ b/src/build.py @@ -144,6 +144,8 @@ class Build: file = f"{id}.jpg" try: shutil.copyfile(self.config.p_data_photos / file, self.config.p_build_photos / file) + if (self.config.p_data_photos / f"{id}.txt").exists(): + return (self.config.p_data_photos / f"{id}.txt").read_text() except FileNotFoundError: tqdm.write(f"\033[31mPhoto #{id} not found\033[0m") diff --git a/src/download.py b/src/download.py index 684fdd7..fd443f6 100644 --- a/src/download.py +++ b/src/download.py @@ -92,10 +92,19 @@ class Download: photos = self.api.get("items/Fotos", params={"limit": -1}) for photo in tqdm(photos, desc="Downloading photos"): + # Save Photo to file data = self.api.get_file("assets/" + photo["photo"]) with (self.config.p_data_photos / f"{photo['id']}.jpg").open("wb") as file: file.write(data) + # Save Alt-Text to file + prefix = "" + if photo["alt_text"] is not None: + if photo["alt_text_reviewed"] is None: + prefix = "Der folgende Alt-Text wurde noch nicht geprüft: " + with (self.config.p_data_photos / f"{photo['id']}.txt").open("w") as file: + file.write(prefix + photo["alt_text"]) + def download_pictures(self): self.config.p_data_pictures.mkdir(parents=True, exist_ok=True) diff --git a/test/test_photo.py b/test/test_photo.py index 6e0c042..60d243d 100644 --- a/test/test_photo.py +++ b/test/test_photo.py @@ -9,7 +9,9 @@ from test.util import paragraph @pytest.mark.html def test_photo_html(): assertions = { - "[photo:123:abc:Text]": FiftyOhmHtmlRenderer.render_photo_helper("123", "abc", "Text", "TODO"), + "[photo:123:abc:Text]": FiftyOhmHtmlRenderer.render_photo_helper( + "123", "abc", "Text", "TODO", "Alt-Text noch nicht verfügbar" + ), } for assertion in assertions: From f7746fe7a407be0ddcf4f06e7087670141e92c74 Mon Sep 17 00:00:00 2001 From: Tim Grelka Date: Fri, 9 Jan 2026 20:53:53 +0100 Subject: [PATCH 5/5] =?UTF-8?q?reactor:=20don=E2=80=98t=20include=20defaul?= =?UTF-8?q?t=20alt=20text=20in=20render=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- renderer/fifty_ohm_html_renderer.py | 6 +++--- src/build.py | 4 ++++ test/test_photo.py | 4 +--- test/test_picture.py | 4 +--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/renderer/fifty_ohm_html_renderer.py b/renderer/fifty_ohm_html_renderer.py index e50bcac..d83ebab 100644 --- a/renderer/fifty_ohm_html_renderer.py +++ b/renderer/fifty_ohm_html_renderer.py @@ -199,9 +199,9 @@ class FiftyOhmHtmlRenderer(HtmlRenderer): """ def render_picture(self, token): - alt_text = "Alt-Text noch nicht verfügbar" + alt_text = "" if self.picture_handler is not None: - alt_text = self.picture_handler(token.id) or alt_text + alt_text = self.picture_handler(token.id) return self.render_picture_helper(token.id, token.ref, token.text, token.number, alt_text) @@ -215,7 +215,7 @@ class FiftyOhmHtmlRenderer(HtmlRenderer): """ def render_photo(self, token): - alt_text = "Alt-Text noch nicht verfügbar" + alt_text = "" if self.photo_handler is not None: alt_text = self.photo_handler(token.id) or alt_text return self.render_photo_helper(token.id, token.ref, token.text, token.number, alt_text) diff --git a/src/build.py b/src/build.py index 0729531..26f9cdd 100644 --- a/src/build.py +++ b/src/build.py @@ -136,6 +136,8 @@ class Build: shutil.copyfile(self.config.p_data_pictures / file, self.config.p_build_pictures / file) if (self.config.p_data_pictures / f"{id}.txt").exists(): return (self.config.p_data_pictures / f"{id}.txt").read_text() + else: + return "Bildbeschreibung noch nicht verfügbar" except FileNotFoundError: tqdm.write(f"\033[31mPicture #{id} not found\033[0m") @@ -146,6 +148,8 @@ class Build: shutil.copyfile(self.config.p_data_photos / file, self.config.p_build_photos / file) if (self.config.p_data_photos / f"{id}.txt").exists(): return (self.config.p_data_photos / f"{id}.txt").read_text() + else: + return "Bildbeschreibung noch nicht verfügbar" except FileNotFoundError: tqdm.write(f"\033[31mPhoto #{id} not found\033[0m") diff --git a/test/test_photo.py b/test/test_photo.py index 60d243d..7e6d27b 100644 --- a/test/test_photo.py +++ b/test/test_photo.py @@ -9,9 +9,7 @@ from test.util import paragraph @pytest.mark.html def test_photo_html(): assertions = { - "[photo:123:abc:Text]": FiftyOhmHtmlRenderer.render_photo_helper( - "123", "abc", "Text", "TODO", "Alt-Text noch nicht verfügbar" - ), + "[photo:123:abc:Text]": FiftyOhmHtmlRenderer.render_photo_helper("123", "abc", "Text", "TODO", ""), } for assertion in assertions: diff --git a/test/test_picture.py b/test/test_picture.py index ea1eced..d9bb240 100644 --- a/test/test_picture.py +++ b/test/test_picture.py @@ -9,9 +9,7 @@ from test.util import paragraph @pytest.mark.html def test_picture_html(): assertions = { - "[picture:0:abc:Text]": FiftyOhmHtmlRenderer.render_picture_helper( - "0", "abc", "Text", "TODO", "Alt-Text noch nicht verfügbar" - ), + "[picture:0:abc:Text]": FiftyOhmHtmlRenderer.render_picture_helper("0", "abc", "Text", "TODO", ""), } for assertion in assertions: