.
This commit is contained in:
+18
-3
@@ -439,23 +439,38 @@ def print_preview(request):
|
||||
except Exception:
|
||||
design = 1
|
||||
scale = float(data.get('scale', '1')) if data.get('scale') else 1.0
|
||||
try:
|
||||
per_page = int(data.get('per_page', '2'))
|
||||
except Exception:
|
||||
per_page = 2
|
||||
if per_page not in (1, 2, 4):
|
||||
per_page = 2
|
||||
# Fetch cards preserving the given order
|
||||
cards = list(Dinosaur.objects.filter(pk__in=pks))
|
||||
# Reorder according to provided pks
|
||||
pk_to_card = {str(c.pk): c for c in cards}
|
||||
ordered = [pk_to_card[pk] for pk in pks if pk in pk_to_card]
|
||||
|
||||
# Build pages: two cards per A4 page (2-up)
|
||||
# Build pages: per_page cards per A4 page
|
||||
pages = []
|
||||
per_page = 2
|
||||
for i in range(0, len(ordered), per_page):
|
||||
pages.append(ordered[i:i+per_page])
|
||||
|
||||
# Determine grid columns for layout: use 1 column for 1-up, 2 columns for 2/4-up
|
||||
columns = 1 if per_page == 1 else 2
|
||||
|
||||
# Include the active background (if any) so fragments that fall back to
|
||||
# a global `background` variable can render correctly in the printable view.
|
||||
background = BackgroundImage.get_active() if BackgroundImage.objects.exists() else None
|
||||
|
||||
return render(request, 'cards/printable.html', {'pages': pages, 'design': design, 'scale': scale, 'background': background})
|
||||
return render(request, 'cards/printable.html', {
|
||||
'pages': pages,
|
||||
'design': design,
|
||||
'scale': scale,
|
||||
'background': background,
|
||||
'per_page': per_page,
|
||||
'columns': columns,
|
||||
})
|
||||
|
||||
|
||||
def _parse_pasted_input(text):
|
||||
|
||||
Reference in New Issue
Block a user