mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-01 21:16:46 +00:00
Add debug option to the sheet printer plugin (#7614)
This commit is contained in:
parent
5e040c4dc4
commit
4e6879407e
@ -12,6 +12,7 @@ import weasyprint
|
|||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
import report.helpers
|
import report.helpers
|
||||||
|
from InvenTree.helpers import str2bool
|
||||||
from plugin import InvenTreePlugin
|
from plugin import InvenTreePlugin
|
||||||
from plugin.mixins import LabelPrintingMixin, SettingsMixin
|
from plugin.mixins import LabelPrintingMixin, SettingsMixin
|
||||||
from report.models import LabelOutput, LabelTemplate
|
from report.models import LabelOutput, LabelTemplate
|
||||||
@ -64,9 +65,22 @@ class InvenTreeLabelSheetPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlug
|
|||||||
|
|
||||||
BLOCKING_PRINT = True
|
BLOCKING_PRINT = True
|
||||||
|
|
||||||
SETTINGS = {}
|
SETTINGS = {
|
||||||
|
'DEBUG': {
|
||||||
|
'name': _('Debug mode'),
|
||||||
|
'description': _('Enable debug mode - returns raw HTML instead of PDF'),
|
||||||
|
'validator': bool,
|
||||||
|
'default': False,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PrintingOptionsSerializer = LabelPrintingOptionsSerializer
|
PrintingOptionsSerializer = LabelPrintingOptionsSerializer
|
||||||
|
debug = None
|
||||||
|
|
||||||
|
def in_debug_mode(self):
|
||||||
|
"""Check if the plugin is printing in debug mode."""
|
||||||
|
if self.debug is None:
|
||||||
|
self.debug = str2bool(self.get_setting('DEBUG'))
|
||||||
|
|
||||||
def print_labels(
|
def print_labels(
|
||||||
self, label: LabelTemplate, output: LabelOutput, items: list, request, **kwargs
|
self, label: LabelTemplate, output: LabelOutput, items: list, request, **kwargs
|
||||||
@ -135,11 +149,15 @@ class InvenTreeLabelSheetPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlug
|
|||||||
# Render to a single HTML document
|
# Render to a single HTML document
|
||||||
html_data = self.wrap_pages(pages, **document_data)
|
html_data = self.wrap_pages(pages, **document_data)
|
||||||
|
|
||||||
# Render HTML to PDF
|
if self.in_debug_mode():
|
||||||
html = weasyprint.HTML(string=html_data)
|
# Render HTML to PDF
|
||||||
document = html.render().write_pdf()
|
html = weasyprint.HTML(string=html_data)
|
||||||
|
document = html.render().write_pdf()
|
||||||
|
|
||||||
|
output.output = ContentFile(document, 'labels.pdf')
|
||||||
|
else:
|
||||||
|
output.output = ContentFile(html_data, 'labels.html')
|
||||||
|
|
||||||
output.output = ContentFile(document, 'labels.pdf')
|
|
||||||
output.progress = 100
|
output.progress = 100
|
||||||
output.complete = True
|
output.complete = True
|
||||||
output.save()
|
output.save()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user