Skip to content

Commit

Permalink
move to a slightly newer pandoc?
Browse files Browse the repository at this point in the history
  • Loading branch information
ewdurbin committed Dec 18, 2023
1 parent b73c2d4 commit ef04c34
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Aptfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ pandoc
texlive-latex-base
texlive-latex-recommended
texlive-fonts-recommended
texlive-plain-generic
lmodern
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.9-bullseye
FROM python:3.9-bookworm
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion base-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 10 additions & 6 deletions sponsors/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()

Expand All @@ -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,
Expand Down

0 comments on commit ef04c34

Please sign in to comment.