From 6d19844e22739779e3bbb1f9f49f831202b81dea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Bedna=C5=99=C3=ADk?= <jan.bednarik@gmail.com>
Date: Fri, 23 Jul 2021 20:53:13 +0200
Subject: [PATCH] elections2021: Exports by ministry

---
 .../management/commands/export_program.py      | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/elections2021/management/commands/export_program.py b/elections2021/management/commands/export_program.py
index 0f1065d2..4fc22ba6 100644
--- a/elections2021/management/commands/export_program.py
+++ b/elections2021/management/commands/export_program.py
@@ -86,15 +86,18 @@ def plain_export(output_file, output_format):
             file.write(content)
 
 
-def fancy_export(output_file):
+def fancy_export(output_file, ministry=None):
     tmp_file = f"{output_file}.tmp"
     benefits_titles = dict(BENEFITS_CHOICES)
 
-    pages = (
-        Elections2021ProgramPointPage.objects.live()
-        .specific()
-        .order_by("-default_order")
-    )
+    if ministry is None:
+        pages = (
+            Elections2021ProgramPointPage.objects.live()
+            .specific()
+            .order_by("-default_order")
+        )
+    else:
+        pages = get_ministry_points(ministry)
 
     points = []
     for page in pages:
@@ -133,6 +136,7 @@ class Command(BaseCommand):
     def add_arguments(self, parser):
         parser.add_argument("output", type=str, help=".pdf nebo .html soubor")
         parser.add_argument("--fancy", action="store_true")
+        parser.add_argument("--ministry", type=str)
 
     def handle(self, *args, **options):
         output_file = options["output"]
@@ -147,6 +151,6 @@ class Command(BaseCommand):
         if options["fancy"]:
             if output_format != FORMAT_PDF:
                 raise CommandError("Fancy export lze udělat jen do .pdf")
-            fancy_export(output_file)
+            fancy_export(output_file, options["ministry"])
         else:
             plain_export(output_file, output_format)
-- 
GitLab