From 2667ecb6b852bcf8fe4557f11f6c22b82331a223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bedna=C5=99=C3=ADk?= <jan.bednarik@gmail.com> Date: Mon, 31 May 2021 23:57:16 +0200 Subject: [PATCH] elections2021: Fix export --- elections2021/management/commands/export_program.py | 7 +++++-- .../templates/elections2021/export_program_point.html | 2 +- elections2021/templatetags/elections2021_extras.py | 5 +++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/elections2021/management/commands/export_program.py b/elections2021/management/commands/export_program.py index 0d16f0d7..265c423c 100644 --- a/elections2021/management/commands/export_program.py +++ b/elections2021/management/commands/export_program.py @@ -5,7 +5,7 @@ from django.template.loader import render_to_string from django.utils import timezone from weasyprint import CSS, HTML -from ...constants import MINISTRY_CHOICES, MINISTRY_CODES +from ...constants import BENEFITS_CHOICES, MINISTRY_CHOICES, MINISTRY_CODES from ...models import Elections2021ProgramPointPage @@ -19,6 +19,8 @@ class Command(BaseCommand): parser.add_argument("output", type=str, help=".pdf nebo .html soubor") def handle(self, *args, **options): + benefits_titles = {num: title for num, title in BENEFITS_CHOICES} + toc = [] body = [] @@ -27,7 +29,8 @@ class Command(BaseCommand): points = [] for page in get_ministry_points(ministry): value = render_to_string( - "elections2021/export_program_point.html", {"page": page} + "elections2021/export_program_point.html", + {"page": page, "benefits_titles": benefits_titles}, ) value = re.sub(r'href="#zdroje"', f'href="#zdroje_{page.id}"', value) points.append(value) diff --git a/elections2021/templates/elections2021/export_program_point.html b/elections2021/templates/elections2021/export_program_point.html index a04925f0..50121877 100644 --- a/elections2021/templates/elections2021/export_program_point.html +++ b/elections2021/templates/elections2021/export_program_point.html @@ -27,7 +27,7 @@ <h3 class="section-title">Pro koho to chceme hlavnÄ›</h3> <div> {% for block in page.benefits_main %} - <h4>{{ block.value.title }}</h4> + <h4>{{ benefits_titles|dictitem:block.value.variant }}</h4> <div>{{ block.value.text|richtext|format_sources }}</div> {% endfor %} {% for block in page.benefits %} diff --git a/elections2021/templatetags/elections2021_extras.py b/elections2021/templatetags/elections2021_extras.py index 7a43be23..4f8feb0c 100644 --- a/elections2021/templatetags/elections2021_extras.py +++ b/elections2021/templatetags/elections2021_extras.py @@ -66,3 +66,8 @@ def strip_sup(value): for sup in soup.find_all("sup"): sup.decompose() return str(soup) + + +@register.filter +def dictitem(dictionary, key): + return dictionary.get(key) -- GitLab