From d30852e5f10ce6ddf1d6fa190ad0cb30223c67c1 Mon Sep 17 00:00:00 2001 From: James Polley Date: Sun, 7 Jan 2018 23:15:32 +1100 Subject: [PATCH] Attach qrcode as attachment --- vendor/regidesk/regidesk/views.py | 32 ++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/vendor/regidesk/regidesk/views.py b/vendor/regidesk/regidesk/views.py index c10eee04..52a0e2ec 100644 --- a/vendor/regidesk/regidesk/views.py +++ b/vendor/regidesk/regidesk/views.py @@ -1,6 +1,7 @@ import base64 import logging from datetime import datetime +from email.mime.image import MIMEImage from django.core.exceptions import ValidationError from django.core.mail import EmailMultiAlternatives @@ -169,7 +170,7 @@ def boarding_send(request): "user": user, "checkin": user.checkin, "code": user.checkin.code, - "qrcode": user.checkin.qrcode, + "qrcode": '', "qrcode_url": request.build_absolute_uri( reverse("regidesk:checkin_png", args=[user.checkin.code])), } @@ -188,29 +189,34 @@ def boarding_send(request): html_body=html_body ) bpass.save() + if user.checkin.boardingpass: user.checkin.boardingpass.delete() user.checkin.boardingpass = bpass user.checkin.save() - with transaction.atomic(): + msg = EmailMultiAlternatives( + bpass.subject, + bpass.body, + bpass.from_address, + [bpass.to_address,], + ) + msg.content_subtype="html" + msg.mixed_subtype="related" + if bpass.html_body: + msg.attach_alternative(bpass.html_body, "text/html") - msg = EmailMultiAlternatives( - bpass.subject, - bpass.body, - bpass.from_address, - [bpass.to_address,], - ) - if bpass.html_body: - msg.attach_alternative(bpass.html_body, "text/html") + qrcode_image = MIMEImage(base64.b64decode(user.checkin.qrcode)) + qrcode_image.add_header('Content-ID', '') + msg.attach(qrcode_image) - if user in boarding_users: + if user in boarding_users: + with transaction.atomic(): msg.send() - bpass.sent = datetime.now() bpass.save() messages.success(request, "Sent boarding pass to %s" % attendee) - request.session['boarding_attendees'].remove(attendee.pk) + request.session['boarding_attendees'].remove(attendee.pk) return redirect("regidesk:boarding_overview")