-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
20 changed files
with
483 additions
and
605 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,9 @@ | ||
FROM python:3.9-bookworm | ||
FROM python:3.9-bullseye | ||
ENV PYTHONUNBUFFERED=1 | ||
ENV PYTHONDONTWRITEBYTECODE=1 | ||
|
||
# By default, Docker has special steps to avoid keeping APT caches in the layers, which | ||
# is good, but in our case, we're going to mount a special cache volume (kept between | ||
# builds), so we WANT the cache to persist. | ||
RUN set -eux; \ | ||
rm -f /etc/apt/apt.conf.d/docker-clean; \ | ||
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache; | ||
|
||
# Install System level build requirements, this is done before | ||
# everything else because these are rarely ever going to change. | ||
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ | ||
--mount=type=cache,target=/var/lib/apt,sharing=locked \ | ||
set -x \ | ||
&& apt-get update \ | ||
&& apt-get install --no-install-recommends -y \ | ||
pandoc \ | ||
texlive-latex-base \ | ||
texlive-latex-recommended \ | ||
texlive-fonts-recommended \ | ||
texlive-plain-generic \ | ||
lmodern | ||
|
||
RUN case $(uname -m) in \ | ||
"x86_64") ARCH=amd64 ;; \ | ||
"aarch64") ARCH=arm64 ;; \ | ||
esac \ | ||
&& wget --quiet https://github.com/jgm/pandoc/releases/download/2.17.1.1/pandoc-2.17.1.1-1-${ARCH}.deb \ | ||
&& dpkg -i pandoc-2.17.1.1-1-${ARCH}.deb | ||
|
||
RUN mkdir /code | ||
WORKDIR /code | ||
|
||
COPY dev-requirements.txt /code/ | ||
COPY base-requirements.txt /code/ | ||
|
||
RUN pip --no-cache-dir --disable-pip-version-check install --upgrade pip setuptools wheel | ||
|
||
RUN --mount=type=cache,target=/root/.cache/pip \ | ||
set -x \ | ||
&& pip --disable-pip-version-check \ | ||
install \ | ||
-r dev-requirements.txt | ||
|
||
RUN pip install -r dev-requirements.txt | ||
COPY . /code/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,6 +173,7 @@ | |
'ordered_model', | ||
'widget_tweaks', | ||
'django_countries', | ||
'easy_pdf', | ||
'sorl.thumbnail', | ||
|
||
'banners', | ||
|
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
""" | ||
This module is a wrapper around django-easy-pdf so we can reuse code | ||
""" | ||
import io | ||
import os | ||
from django.conf import settings | ||
from django.http import HttpResponse | ||
from django.utils.dateformat import format | ||
|
||
from docxtpl import DocxTemplate | ||
from easy_pdf.rendering import render_to_pdf_response, render_to_pdf | ||
|
||
from markupfield_helpers.helpers import render_md | ||
from django.utils.html import mark_safe | ||
|
||
|
||
def _clean_split(text, separator='\n'): | ||
return [ | ||
t.replace('-', '').strip() | ||
for t in text.split('\n') | ||
if t.replace('-', '').strip() | ||
] | ||
|
||
|
||
def _contract_context(contract, **context): | ||
start_date = contract.sponsorship.start_date | ||
context.update({ | ||
"contract": contract, | ||
"start_date": start_date, | ||
"start_day_english_suffix": format(start_date, "S"), | ||
"sponsor": contract.sponsorship.sponsor, | ||
"sponsorship": contract.sponsorship, | ||
"benefits": _clean_split(contract.benefits_list.raw), | ||
"legal_clauses": _clean_split(contract.legal_clauses.raw), | ||
"renewal": contract.sponsorship.renewal, | ||
}) | ||
previous_effective = contract.sponsorship.previous_effective_date | ||
context["previous_effective"] = previous_effective if previous_effective else "UNKNOWN" | ||
context["previous_effective_english_suffix"] = format(previous_effective, "S") if previous_effective else None | ||
return context | ||
|
||
|
||
def render_contract_to_pdf_response(request, contract, **context): | ||
template = "sponsors/admin/preview-contract.html" | ||
context = _contract_context(contract, **context) | ||
return render_to_pdf_response(request, template, context) | ||
|
||
|
||
def render_contract_to_pdf_file(contract, **context): | ||
template = "sponsors/admin/preview-contract.html" | ||
context = _contract_context(contract, **context) | ||
return render_to_pdf(template, context) | ||
|
||
|
||
def _gen_docx_contract(output, contract, **context): | ||
context = _contract_context(contract, **context) | ||
renewal = context["renewal"] | ||
if renewal: | ||
template = os.path.join(settings.TEMPLATES_DIR, "sponsors", "admin", "renewal-contract-template.docx") | ||
else: | ||
template = os.path.join(settings.TEMPLATES_DIR, "sponsors", "admin", "contract-template.docx") | ||
doc = DocxTemplate(template) | ||
doc.render(context) | ||
doc.save(output) | ||
return output | ||
|
||
|
||
def render_contract_to_docx_response(request, contract, **context): | ||
response = HttpResponse(content_type='application/vnd.openxmlformats-officedocument.wordprocessingml.document') | ||
response['Content-Disposition'] = 'attachment; filename=contract.docx' | ||
return _gen_docx_contract(output=response, contract=contract, **context) | ||
|
||
|
||
def render_contract_to_docx_file(contract, **context): | ||
fp = io.BytesIO() | ||
fp = _gen_docx_contract(output=fp, contract=contract, **context) | ||
fp.seek(0) | ||
return fp.read() |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.