diff options
| author | Magnus Hagander | 2019-11-05 18:59:35 +0000 |
|---|---|---|
| committer | Magnus Hagander | 2019-11-05 19:05:36 +0000 |
| commit | 0ef3b472aae2ed693b16d3da95b1562fefa1e6cd (patch) | |
| tree | 82db6192b0248ddd46aba8ccd340f073358d27a7 /postgresqleu/util/misc | |
| parent | 67ee0f4eeced616c195b6d13b4d018e5b072c2f5 (diff) | |
Make loading of qrencode and cairosvg optional
In particular, cairosvg is only used for the PNG format twitter cards,
so most functionality exists without it.
Make sure we import those modules conditionally only when needed and
handle the import exception. Also add an explicit attempt to load them
during system startup and write to the log if it fails, so it doesn't do
so silently.
Diffstat (limited to 'postgresqleu/util/misc')
| -rwxr-xr-x | postgresqleu/util/misc/baseinvoice.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/postgresqleu/util/misc/baseinvoice.py b/postgresqleu/util/misc/baseinvoice.py index 8d79492e..834f37bc 100755 --- a/postgresqleu/util/misc/baseinvoice.py +++ b/postgresqleu/util/misc/baseinvoice.py @@ -13,7 +13,6 @@ from reportlab.platypus.tables import Table, TableStyle from reportlab.platypus.flowables import Image from reportlab.pdfbase.pdfmetrics import registerFont, getFont from reportlab.pdfbase.ttfonts import TTFont -import qrencode from io import BytesIO from django.conf import settings @@ -324,11 +323,17 @@ class BaseInvoice(PDFBase): p.wrapOn(self.canvas, cm(12), cm(2)) p.drawOn(self.canvas, cm(2), cm(3.5)) - (ver, size, qrimage) = qrencode.encode(self.paymentlink) - qrimage = qrimage.resize((size * 4, size * 4)) - self.canvas.drawImage(ImageReader(qrimage), - cm(2), cm(1.8), - cm(1.5), cm(1.5)) + try: + import qrencode + (ver, size, qrimage) = qrencode.encode(self.paymentlink) + qrimage = qrimage.resize((size * 4, size * 4)) + self.canvas.drawImage(ImageReader(qrimage), + cm(2), cm(1.8), + cm(1.5), cm(1.5)) + except ImportError: + # If we don't have the qrcode module, we just don't bother drawing the + # QR code for the link + pass if self.reverse_vat: t = self.canvas.beginText() |
