diff --git a/elections2021/management/commands/export_program.py b/elections2021/management/commands/export_program.py index 0d16f0d70754e6b82f3b9ae07cd234bc3575d5ff..265c423c3647e0d504d7202d66bb6f0cafa29087 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 a04925f09df6afe01bd0a2bff83eb60205961299..50121877be36dc114b0cddeab0855f97aaea8789 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 7a43be23fceccf6b3e4c6c0cdec04414042f0db6..4f8feb0cc76c3a2a09d5af381c7cce01504c0e31 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)