From ef04c3420f13ed63e09f6bbaf7065c7e874b662a Mon Sep 17 00:00:00 2001 From: Ee Durbin Date: Mon, 18 Dec 2023 05:05:33 -0500 Subject: [PATCH] move to a slightly newer pandoc? --- .github/workflows/ci.yml | 6 +++++- Aptfile | 1 + Dockerfile | 3 ++- base-requirements.txt | 2 +- sponsors/contracts.py | 16 ++++++++++------ 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b7f1c961b..9d2a67f96 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,11 @@ jobs: - name: Install platform dependencies run: | sudo apt -y update - sudo apt -y install $(cat Aptfile | xargs) + sudo apt -y install $(cat Aptfile | grep -v '^pandoc$' | xargs) + - name: Install pandoc + run: | + wget https://github.com/jgm/pandoc/releases/download/2.17.1.1/pandoc-2.17.1.1-1-amd64.deb + sudo dpkg -i pandoc-2.17.1.1-1-amd64.deb - uses: actions/setup-python@v2 with: python-version: 3.9.16 diff --git a/Aptfile b/Aptfile index bc0db6c25..0f5b752cb 100644 --- a/Aptfile +++ b/Aptfile @@ -2,4 +2,5 @@ pandoc texlive-latex-base texlive-latex-recommended texlive-fonts-recommended +texlive-plain-generic lmodern diff --git a/Dockerfile b/Dockerfile index aec467d40..e918e7e0a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.9-bullseye +FROM python:3.9-bookworm ENV PYTHONUNBUFFERED=1 ENV PYTHONDONTWRITEBYTECODE=1 @@ -20,6 +20,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ texlive-latex-base \ texlive-latex-recommended \ texlive-fonts-recommended \ + texlive-plain-generic \ lmodern RUN mkdir /code diff --git a/base-requirements.txt b/base-requirements.txt index 515ceffae..2495153db 100644 --- a/base-requirements.txt +++ b/base-requirements.txt @@ -51,4 +51,4 @@ django-extensions==3.1.4 django-import-export==2.7.1 pypandoc==1.12 -panflute==1.12 +panflute==2.3.0 diff --git a/sponsors/contracts.py b/sponsors/contracts.py index 983cc3ae2..1ed86cd5b 100644 --- a/sponsors/contracts.py +++ b/sponsors/contracts.py @@ -35,6 +35,12 @@ def _contract_context(contract, **context): return context +def render_markdown_from_template(contract, **context): + template = "sponsors/admin/contracts/sponsorship-agreement.md" + context = _contract_context(contract, **context) + return render_to_string(template, context) + + def render_contract_to_pdf_response(request, contract, **context): response = HttpResponse( render_contract_to_pdf_file(contract, **context), content_type="application/pdf" @@ -45,9 +51,9 @@ def render_contract_to_pdf_response(request, contract, **context): def render_contract_to_pdf_file(contract, **context): with tempfile.NamedTemporaryFile() as docx_file: with tempfile.NamedTemporaryFile(suffix=".pdf") as pdf_file: - docx_file.write(render_contract_to_docx_file(contract, **context)) - pdf = pypandoc.convert_file( - docx_file.name, "pdf", outputfile=pdf_file.name, format="docx" + markdown = render_markdown_from_template(contract, **context) + pdf = pypandoc.convert_text( + markdown, "pdf", outputfile=pdf_file.name, format="md" ) return pdf_file.read() @@ -64,10 +70,8 @@ def render_contract_to_docx_response(request, contract, **context): def render_contract_to_docx_file(contract, **context): - template = "sponsors/admin/contracts/sponsorship-agreement.md" reference = "sponsors/admin/contracts/reference.docx" - context = _contract_context(contract, **context) - markdown = render_to_string(template, context) + markdown = render_markdown_from_template(contract, **context) with tempfile.NamedTemporaryFile() as docx_file: docx = pypandoc.convert_text( markdown,