Skip to content

Commit

Permalink
Default to existing behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
Syfaro committed Nov 10, 2024
1 parent 67a41d0 commit 3510413
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
9 changes: 5 additions & 4 deletions registration/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,16 +946,17 @@ def get_attendee_age(attendee):


def print_badges(modeladmin, request, queryset):
if settings.PRINT_RENDERER == "wkhtmltopdf":
pdf_name = generate_badge_labels(queryset, request)
pdf_path = reverse("registration:pdf") + f"?file={pdf_name}"
else:
if getattr(settings, "PRINT_RENDERER", "wkhtmltopdf") == "gotenberg":
signer = TimestampSigner()
data = signer.sign_object({
"badge_ids": [badge.id for badge in queryset],
})

pdf_path = reverse("registration:pdf") + f"?data={data}"
else:
pdf_name = generate_badge_labels(queryset, request)
pdf_path = reverse("registration:pdf") + f"?file={pdf_name}"


response = HttpResponseRedirect(reverse("registration:print"))
url_params = {"file": pdf_path, "next": request.get_full_path()}
Expand Down
20 changes: 10 additions & 10 deletions registration/views/onsite_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,16 +345,7 @@ def get_messages_list(request):
def onsite_print_badges(request):
badge_list = request.GET.getlist("id")

if settings.PRINT_RENDERER == "wkhtmltopdf":
queryset = Badge.objects.filter(id__in=badge_list)
pdf_name = admin.generate_badge_labels(queryset, request)

pdf_path = reverse("registration:pdf") + f"?file={pdf_name}"

# Async notify the frontend to refresh the cart
logger.info("Refreshing admin cart")
admin_push_cart_refresh(request)
else:
if getattr(settings, "PRINT_RENDERER", "wkhtmltopdf") == "gotenberg":
terminal = get_active_terminal(request)

signer = TimestampSigner()
Expand All @@ -364,6 +355,15 @@ def onsite_print_badges(request):
})

pdf_path = reverse("registration:pdf") + f"?data={data}"
else:
queryset = Badge.objects.filter(id__in=badge_list)
pdf_name = admin.generate_badge_labels(queryset, request)

pdf_path = reverse("registration:pdf") + f"?file={pdf_name}"

# Async notify the frontend to refresh the cart
logger.info("Refreshing admin cart")
admin_push_cart_refresh(request)

print_url = reverse("registration:print") + "?" + urlencode({"file": pdf_path})

Expand Down
5 changes: 3 additions & 2 deletions registration/views/printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def printNametag(request):


def servePDF(request):
if settings.PRINT_RENDERER == "gotenberg":
if getattr(settings, "PRINT_RENDERER", "wkhtmltopdf") == "gotenberg":
return pdfFromGotenberg(request)
else:
return pdfFromDisk(request.GET.get("file", None))
Expand All @@ -43,8 +43,9 @@ def pdfFromDisk(name: Optional[str]) -> Union[FileResponse, JsonResponse]:
{"success": False, "reason": "Name was missing"}, status=400
)

root_dir = getattr(settings, "PDF_DIRECTORY", "/tmp")
try:
path = Path(settings.PDF_DIRECTORY).joinpath(Path(name).name)
path = Path(root_dir).joinpath(Path(name).name)
f = open(path, "rb")
except IOError:
return JsonResponse({"success": False, "reason": "IO error"}, status=404)
Expand Down

0 comments on commit 3510413

Please sign in to comment.