From f77e1498f12878cd3001f3c06052eb9800fd2da6 2017-12-27 11:42:15 From: Sachi King Date: 2017-12-27 11:42:15 Subject: [PATCH] Mgmt command for boarding pass mailout Slowly but surely sends boarding passes out. Has template for html and txt sepearte so we can try to direct users to HTML to get the base64 image. We may consider adding the image as an attachment as well as the in-line to allow it to be opened in plain-text emails, but I don't know if that's desired. Just a base, templates will need to be spell checked and spruced up before sendout. But this will provide the tool to send the boarding pass out. Now we need a UI for front-desk to use. --- diff --git a/vendor/registrasion/registrasion/management/commands/send_boarding_pass_mailout.py b/vendor/registrasion/registrasion/management/commands/send_boarding_pass_mailout.py new file mode 100644 index 0000000000000000000000000000000000000000..c3d30fc0cf24a3f95fd4abd7f2d579e71708f0cf --- /dev/null +++ b/vendor/registrasion/registrasion/management/commands/send_boarding_pass_mailout.py @@ -0,0 +1,61 @@ +import base64 +import io + +from django.conf import settings +from django.core.management.base import BaseCommand +from django.core.mail import EmailMultiAlternatives +from django.template.loader import render_to_string +import pyqrcode + +from registrasion.models import commerce + +class Command(BaseCommand): + + def handle(self, *args, **options): + try: + bcc_email = settings.ENVELOPE_BCC_LIST + except AttributeError: + bcc_email = None + + invoices = commerce.Invoice.objects.filter( + user__attendee__boarding_pass_sent=False, + status=commerce.Cart.STATUS_PAID, + ).order_by("-issue_time") + + for invoice in invoices: + access_code = invoice.user.attendee.access_code + + acqr = pyqrcode.create(access_code) + acqr_png = io.BytesIO() + acqr.png(acqr_png, scale=6) + acqr_png.seek(0) + + img = acqr_png.read() + b64image = base64.b64encode(img).decode('UTF-8') + + context = { + "qr_code_string": b64image, + "access_code": access_code, + } + subject_path = 'registrasion/emails/boarding_pass/subject.txt' + html_path = 'registrasion/emails/boarding_pass/message.html' + txt_path = 'registrasion/emails/boarding_pass/message.txt' + subject = "[linux.conf.au] %s" % ( + render_to_string(subject_path, {}).strip() + ) + message_html = render_to_string(html_path, context) + message_txt = render_to_string(txt_path, context) + + msg = EmailMultiAlternatives( + subject, + message_txt, + settings.DEFAULT_FROM_EMAIL, + [invoice.user.email], + bcc=bcc_email, + ) + msg.attach_alternative(message_html, "text/html") + + msg.send() + + invoice.user.attendee.boarding_pass_sent = True + invoice.user.attendee.save() diff --git a/vendor/registrasion/registrasion/migrations/0009_attendee_boarding_pass_sent.py b/vendor/registrasion/registrasion/migrations/0009_attendee_boarding_pass_sent.py new file mode 100644 index 0000000000000000000000000000000000000000..afc8415502ba697a378734f5f980ba22dc5fc68d --- /dev/null +++ b/vendor/registrasion/registrasion/migrations/0009_attendee_boarding_pass_sent.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.8 on 2017-12-27 05:05 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('registrasion', '0008_auto_20170930_1843'), + ] + + operations = [ + migrations.AddField( + model_name='attendee', + name='boarding_pass_sent', + field=models.BooleanField(default=False), + ), + ] diff --git a/vendor/registrasion/registrasion/models/people.py b/vendor/registrasion/registrasion/models/people.py index 561c3bb4ec0a2ed1e7f6e0731e5bf8f4b5475922..e0297b35b9f7cceab80551753491d97bf4b40426 100644 --- a/vendor/registrasion/registrasion/models/people.py +++ b/vendor/registrasion/registrasion/models/people.py @@ -42,6 +42,7 @@ class Attendee(models.Model): unique=True, db_index=True, ) + boarding_pass_sent = models.BooleanField(default=False) completed_registration = models.BooleanField(default=False) guided_categories_complete = models.ManyToManyField("category", blank=True) diff --git a/vendor/registrasion/registrasion/templates/registrasion/emails/boarding_pass/message.html b/vendor/registrasion/registrasion/templates/registrasion/emails/boarding_pass/message.html new file mode 100644 index 0000000000000000000000000000000000000000..50a49590af79c504c20372995e15eb8c8cf4b234 --- /dev/null +++ b/vendor/registrasion/registrasion/templates/registrasion/emails/boarding_pass/message.html @@ -0,0 +1,8 @@ + + +

This is your boarding pass

+

A copy of the QR Code is required for check in, please bring this email on either your phone or on a print out.

+

+

Backup Code: {{ access_code }}

+ + diff --git a/vendor/registrasion/registrasion/templates/registrasion/emails/boarding_pass/message.txt b/vendor/registrasion/registrasion/templates/registrasion/emails/boarding_pass/message.txt new file mode 100644 index 0000000000000000000000000000000000000000..64e9748607d3b9c06f97406da7123a7164423cb2 --- /dev/null +++ b/vendor/registrasion/registrasion/templates/registrasion/emails/boarding_pass/message.txt @@ -0,0 +1,8 @@ +This is the plain text version of your boarding pass for linux.conf.au 2018. + +The HTML version of this email has a QR Code embedded in it, and it would be greatly appricated if you could switch to that version to print or bring on a phone for check in so we may use the QR code to check you in. + + +In the event this cannot be facilitated, please provide the following backup code. + +Backup Code: {{ access_code }} diff --git a/vendor/registrasion/registrasion/templates/registrasion/emails/boarding_pass/subject.txt b/vendor/registrasion/registrasion/templates/registrasion/emails/boarding_pass/subject.txt new file mode 100644 index 0000000000000000000000000000000000000000..c5eabc00fa30d42ee4726816a755fd969f298abb --- /dev/null +++ b/vendor/registrasion/registrasion/templates/registrasion/emails/boarding_pass/subject.txt @@ -0,0 +1 @@ +Your LCA2018 Boarding Pass diff --git a/vendor/registrasion/requirements/base.txt b/vendor/registrasion/requirements/base.txt index c45a3a46730be13cbf7af07884025f339b6b6bab..8107f4415d33ec1c7635e1bd0d570d1febf6de1d 100644 --- a/vendor/registrasion/requirements/base.txt +++ b/vendor/registrasion/requirements/base.txt @@ -1,3 +1,5 @@ django-nested-admin==2.2.6 #symposion==1.0b2.dev3 lxml==4.0.0 +pyqrcode +pypng