Fix weasyprint version (#3539)

* Pin weasyprint version

- Revert to 54.3
- Fixes https://github.com/inventree/InvenTree/issues/3528

* Simplify label printing for multiple pages

* Simplify PDF generation for multiple report outputs

* Add content wrapper div for base label template

- Allows more extensibility
This commit is contained in:
Oliver 2022-08-15 11:27:27 +10:00 committed by GitHub
parent 00dbf00eb9
commit 87e7112326
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 24 deletions

View File

@ -158,16 +158,12 @@ class LabelPrintMixin:
pages = [] pages = []
if len(outputs) > 1:
# If more than one output is generated, merge them into a single file
for output in outputs: for output in outputs:
doc = output.get_document() doc = output.get_document()
for page in doc.pages: for page in doc.pages:
pages.append(page) pages.append(page)
pdf = outputs[0].get_document().copy(pages).write_pdf() pdf = outputs[0].get_document().copy(pages).write_pdf()
else:
pdf = outputs[0].get_document().write_pdf()
inline = common.models.InvenTreeUserSetting.get_setting('LABEL_INLINE', user=request.user) inline = common.models.InvenTreeUserSetting.get_setting('LABEL_INLINE', user=request.user)

View File

@ -15,6 +15,8 @@
margin: 0mm; margin: 0mm;
color: #000; color: #000;
background-color: #FFF; background-color: #FFF;
page-break-before: always;
page-break-after: always;
} }
img { img {
@ -22,14 +24,23 @@
image-rendering: pixelated; image-rendering: pixelated;
} }
.content {
width: 100%;
break-after: always;
position: relative;
}
{% block style %} {% block style %}
/* User-defined styles can go here */
{% endblock %} {% endblock %}
</style> </style>
</head> </head>
<body> <body>
<div class='content'>
{% block content %} {% block content %}
<!-- Label data rendered here! --> <!-- Label data rendered here! -->
{% endblock %} {% endblock %}
</div>
</body> </body>

View File

@ -233,17 +233,12 @@ class ReportPrintMixin:
pages = [] pages = []
try: try:
if len(outputs) > 1:
# If more than one output is generated, merge them into a single file
for output in outputs: for output in outputs:
doc = output.get_document() doc = output.get_document()
for page in doc.pages: for page in doc.pages:
pages.append(page) pages.append(page)
pdf = outputs[0].get_document().copy(pages).write_pdf() pdf = outputs[0].get_document().copy(pages).write_pdf()
else:
pdf = outputs[0].get_document().write_pdf()
except TemplateDoesNotExist as e: except TemplateDoesNotExist as e:

View File

@ -33,6 +33,7 @@ rapidfuzz==0.7.6 # Fuzzy string matching
sentry-sdk # Error reporting (optional) sentry-sdk # Error reporting (optional)
setuptools # Standard depenedency setuptools # Standard depenedency
tablib[xls,xlsx,yaml] # Support for XLS and XLSX formats tablib[xls,xlsx,yaml] # Support for XLS and XLSX formats
weasyprint==54.3 # PDF generation
# Fixed sub-dependencies # Fixed sub-dependencies
py-moneyed<2.0 # For django-money # FIXED 2022-06-18 as we need `moneyed.localization` py-moneyed<2.0 # For django-money # FIXED 2022-06-18 as we need `moneyed.localization`

View File

@ -230,8 +230,10 @@ urllib3==1.26.11
# sentry-sdk # sentry-sdk
wcwidth==0.2.5 wcwidth==0.2.5
# via blessed # via blessed
weasyprint==56.1 weasyprint==54.3
# via django-weasyprint # via
# -r requirements.in
# django-weasyprint
webencodings==0.5.1 webencodings==0.5.1
# via # via
# bleach # bleach