Skip to content
Snippets Groups Projects
Commit abbdfa85 authored by jan.bednarik's avatar jan.bednarik
Browse files

elections2021: Export program improved

parent 05feccb1
Branches
No related tags found
2 merge requests!285elections2021: Export program improved,!284elections2021: Export program improved
Pipeline #3933 passed
......@@ -3,6 +3,8 @@ FROM python:3.8
RUN apt-get update && apt-get install -y \
# requirements for OpenCV
libgl1-mesa-dev \
# requirements for WeasyPrint
python3-cffi \
&& rm -rf /var/lib/apt/lists/*
RUN mkdir /app
......
......@@ -19,53 +19,32 @@ class Command(BaseCommand):
parser.add_argument("output", type=str, help=".pdf nebo .html soubor")
def handle(self, *args, **options):
now = timezone.localtime().strftime("%d.%m.%Y %H:%M")
toc = []
body = []
for ministry, title in MINISTRY_CHOICES:
sub_toc = []
body.append(
f'<h2 id="{ministry}" class="ministry-title">Resort: {title}</h2>'
)
points = []
for page in get_ministry_points(ministry):
value = render_to_string(
"elections2021/export_program_point.html", {"page": page}
)
value = re.sub(r'href="#zdroje"', f'href="#zdroje_{page.id}"', value)
body.append(value)
sub_toc.append(f'<li><a href="#{page.slug}">{page.title}</a></li>')
sub_toc = "".join(sub_toc)
toc.append(
f'<li><a href="#{ministry}">{title}</a><br><ul>{sub_toc}</ul></li>'
)
style = """
body { font-family: "Roboto Condensed", Helvetica, sans-serif; line-height: 1.5; }
.ministry-title { page-break-before: always; margin-bottom: 0; line-height: 1; }
.point-title { border-top: 5px double #AAAAAA; padding-top: 0.5rem; margin-top: 3rem; text-transform: uppercase; }
.section-title { border-top: 1px solid #AAAAAA; padding-top: 0.5rem; margin-top: 2rem; text-transform: uppercase; }
sup { font-size: 70%; }
"""
toc = "".join(toc)
content = (
[
f'<html><head><style type="text/css">{style}</style></head><body>',
"<h1>Program koalice Piráti a Starostové</h1>",
f'<div><p>export z webu <a href="https://www.piratiastarostove.cz/">piratiastarostove.cz</a> z {now}</p></div>',
f"<div><p>obsah:</p><p><ul>{toc}</ul></p></div>",
]
+ body
+ ["</body></html>"]
points.append(value)
sub_toc.append({"anchor": page.slug, "title": page.title})
body.append({"anchor": ministry, "title": title, "points": points})
toc.append({"anchor": ministry, "title": title, "sub_toc": sub_toc})
content = render_to_string(
"elections2021/export_program.html",
{
"toc": toc,
"body": body,
"now": timezone.localtime().strftime("%d.%m.%Y %H:%M"),
},
)
content = "".join(content)
if options["output"].endswith(".pdf"):
html = HTML(string=content)
css = CSS(string="@page { size: A4; margin: 1cm; }")
......
<!doctype html>
<html lang="cs">
<head>
<meta charset="utf-8">
<title>Program koalice Piráti a Starostové</title>
<style type="text/css">
body {
font-family: "Roboto Condensed", Helvetica, sans-serif;
line-height: 1.5;
}
.ministry-title {
page-break-before: always;
margin-bottom: 0;
line-height: 1;
color: #FFFFFF;
background-color: #000000;
padding: 0.5rem;
}
.point-title {
border-top: 5px double #AAAAAA;
padding-top: 0.5rem;
margin-top: 2rem;
text-transform: uppercase;
}
.section-title {
border-top: 1px solid #AAAAAA;
padding-top: 0.5rem;
margin-top: 2rem;
text-transform: uppercase;
}
sup {
font-size: 70%;
}
.last {
margin-bottom: 3rem;
}
</style>
</head>
<body>
<h1>Program koalice Piráti a Starostové</h1>
<div>
<p>export z webu <a href="https://www.piratiastarostove.cz/">piratiastarostove.cz</a> z {{ now }}</p>
<p>obsah:</p>
<ul>
{% for item in toc %}
<li>
<a href="#{{ item.anchor }}">{{ item.title }}</a><br>
<ul>
{% for sub in item.sub_toc %}
<li><a href="#{{ sub.anchor }}">{{ sub.title }}</a></li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
</div>
{% for item in body %}
<h2 id="{{ item.anchor }}" class="ministry-title">Resort: {{ item.title }}</h2>
{% for point in item.points %}
{{ point|safe }}
{% endfor %}
{% endfor %}
</body>
</html>
......@@ -53,4 +53,4 @@
</div>
<h3 class="section-title" id="zdroje_{{ page.id }}">Klidně si to ověřte</h3>
<div>{{ page.sources|richtext }}</div>
<div class="last">{{ page.sources|richtext }}</div>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment