Fix checkin QR code URL

Use site URL in generated emails instead of hard coded domain.
This commit is contained in:
Joel Addison 2020-01-07 16:36:54 +10:00
parent ffd852196b
commit fe6447acae

View file

@ -10,6 +10,7 @@ from django.contrib import messages
from django.contrib.auth.decorators import permission_required, user_passes_test, login_required
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.contrib.auth.models import User, Group
from django.contrib.sites.models import Site
from django.db import transaction
from django.db.models import F, Q
from django.db.models import Count, Max, Sum
@ -126,6 +127,22 @@ def checkin_png(request, checkin_code):
return response
def checkin_qrcode_url(code):
""" Generate the QR code URL for the current site.
eg. https://rego.linux.conf.au/checkin/<code>.png
"""
# Cannot use build_absolute_uri as external URL is not known in docker
# qrcode_url = request.build_absolute_uri(
# reverse("regidesk:checkin_png", args=[code]))
current_site = Site.objects.get_current()
qrcode_url = "https://{}{}".format(current_site,
reverse("regidesk:checkin_png", args=[code]))
return qrcode_url
@permission_required("regidesk.send_boarding_pass")
def boarding_prepare(request):
@ -161,9 +178,7 @@ def boarding_prepare(request):
"boardingpass": sample_checkin.boardingpass,
"code": sample_checkin.code,
"qrcode": '<img src="data:image/png;base64,' + sample_checkin.qrcode + '"/>',
# "qrcode_url": request.build_absolute_uri(
# reverse("regidesk:checkin_png", args=[sample_checkin.code])),
"qrcode_url": "https://rego.linux.conf.au/checkin/" + sample_checkin.code + ".png"
"qrcode_url": checkin_qrcode_url(sample_checkin.code),
}
ctx = Context(sample_ctx)
ctx["invoices"] = invoices(ctx)
@ -205,9 +220,7 @@ def prepare_boarding_pass(user, template, attendee=None):
"checkin": user.checkin,
"code": user.checkin.code,
"qrcode": user.checkin.qrcode,
# "qrcode_url": request.build_absolute_uri(
# reverse("regidesk:checkin_png", args=[user.checkin.code])),
"qrcode_url": "https://rego.linux.conf.au/checkin/" + user.checkin.code + ".png"
"qrcode_url": checkin_qrcode_url(user.checkin.code),
}
ctx = Context(ctx)
ctx["invoices"] = invoices(ctx)