Skip to content
Snippets Groups Projects
Verified Commit e299f045 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Add absolute URL to all static URLs for printing via electron-pdf

parent da0e44bf
No related branches found
No related tags found
1 merge request!464Resolve "Support PDF generation via a headless Chromium running in the background using celery"
......@@ -14,13 +14,13 @@
{{ config.SITE_TITLE }}
</title>
{% include_css "material-design-icons" %}
{% include_css "Roboto" %}
{% include_css "paper-css" %}
<link rel="stylesheet" href="{% sass_src 'style.scss' %}"/>
<link rel="stylesheet" href="{% static "print.css" %}"/>
{% include_css "material-design-icons" prefix=static_prefix %}
{% include_css "Roboto" prefix=static_prefix %}
{% include_css "paper-css" prefix=static_prefix %}
<link rel="stylesheet" href="{{ static_prefix }}{% sass_src 'style.scss' %}"/>
<link rel="stylesheet" href="{{ static_prefix }}{% static "print.css" %}"/>
{% if landscape %}
<link rel="stylesheet" href="{% static 'print_landscape.css' %}"/>
<link rel="stylesheet" href="{{ static_prefix }}{% static 'print_landscape.css' %}"/>
{% endif %}
{% block extra_head %}{% endblock %}
</head>
......@@ -46,8 +46,8 @@
<div id="print-header" class="row">
<div class="col s6 logo">
{% static "img/aleksis-banner.svg" as aleksis_banner %}
<img src="{% firstof request.site.preferences.theme__logo.url aleksis_banner %}" alt="Logo"
id="print-logo"/>
<img src="{{ static_prefix }}{% firstof request.site.preferences.theme__logo.url aleksis_banner %}"
alt="Logo" id="print-logo"/>
</div>
<div class="col s6 right-align">
<h5>{% block page_title %}{% endblock %}</h5>
......
......@@ -30,7 +30,7 @@
</p>
</div>
</noscript>
<div id="messages"></div>
<div id="result-box" style="display: none;">
......
......@@ -12,7 +12,7 @@ from django.utils.translation import gettext as _
from celery_progress.backend import ProgressRecorder
from aleksis.core.celery import app
from aleksis.core.settings import MEDIA_ROOT, MEDIA_URL, STATIC_ROOT
from aleksis.core.settings import MEDIA_ROOT, MEDIA_URL
from aleksis.core.util.celery_progress import recorded_task
from aleksis.core.util.core_helpers import path_and_rename
......@@ -22,9 +22,6 @@ def generate_pdf(html_code: str, pdf_path: str, recorder: ProgressRecorder):
"""Generate a PDF file by rendering the HTML code using electron-pdf."""
recorder.set_progress(0, 1)
# Replace /static with STATIC_ROOT to get local file system paths
html_code = html_code.replace("/static", STATIC_ROOT)
# Open a temporary directory
with TemporaryDirectory() as temp_dir:
# Write HTML code to a temporary file to make it available for electron-pdf
......@@ -56,6 +53,8 @@ def render_pdf(request: HttpRequest, template_name: str, context: dict = None) -
"""
if not context:
context = {}
context.setdefault("static_prefix", request.build_absolute_uri("/")[:-1])
pdf_path = path_and_rename(None, "file.pdf", "pdfs")
html_template = render_to_string(template_name, context)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment