Attach qrcode as attachment
This commit is contained in:
parent
0831a4aa76
commit
d30852e5f1
1 changed files with 19 additions and 13 deletions
32
vendor/regidesk/regidesk/views.py
vendored
32
vendor/regidesk/regidesk/views.py
vendored
|
@ -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": '<img src="cid:qrcode.png"/>',
|
||||
"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', '<qrcode.png>')
|
||||
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")
|
||||
|
|
Loading…
Reference in a new issue