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

Use BASE_URL for PDF generation instead of own preference

parent 9b91f38e
No related branches found
No related tags found
1 merge request!689Support PDF generation without available request object
Pipeline #23869 passed
from django.conf import settings
from django.core.validators import URLValidator
from django.forms import EmailField, ImageField, URLField
from django.forms.widgets import SelectMultiple
from django.utils.translation import gettext_lazy as _
......@@ -53,20 +52,6 @@ class SiteDescription(StringPreference):
verbose_name = _("Site description")
@site_preferences_registry.register
class PDFURL(StringPreference):
"""URL which should be used as base for PDF printing."""
section = general
name = "pdf_url"
default = ""
required = False
verbose_name = _("PDF URL")
help_text = _("This URL is used for PDF printing.")
field_kwargs = {"validators": [URLValidator()]}
@site_preferences_registry.register
class ColourPrimary(StringPreference):
"""Primary colour in AlekSIS frontend."""
......
......@@ -4,6 +4,7 @@ from tempfile import TemporaryDirectory
from typing import Optional, Tuple
from urllib.parse import urljoin
from django.conf import settings
from django.core.files import File
from django.core.files.base import ContentFile
from django.http.request import HttpRequest
......@@ -21,7 +22,6 @@ from celery_progress.backend import ProgressRecorder
from aleksis.core.celery import app
from aleksis.core.models import PDFFile
from aleksis.core.util.celery_progress import recorded_task, render_progress_page
from aleksis.core.util.core_helpers import get_site_preferences
@recorded_task
......@@ -76,12 +76,11 @@ def generate_pdf_from_template(
file_object = PDFFile.objects.create(html_file=ContentFile(html_template, name="source.html"))
# As this method may be run in background and there is no request available,
# we have to use a predefined URL from preferences then
# we have to use a predefined URL from settings then
if request:
html_url = request.build_absolute_uri(file_object.html_file.url)
else:
pdf_base_url = get_site_preferences()["general__pdf_url"]
html_url = urljoin(pdf_base_url, file_object.html_file.url)
html_url = urljoin(settings.BASE_URL, file_object.html_file.url)
result = generate_pdf.delay(file_object.pk, html_url, lang=get_language())
......
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