.
This commit is contained in:
@@ -412,6 +412,48 @@ def export_table(request):
|
||||
return render(request, 'cards/export_table.html', {'json_text': json_text})
|
||||
|
||||
|
||||
def print_cards(request):
|
||||
"""Selection UI where the user picks which cards to print and which design."""
|
||||
qs = Dinosaur.objects.order_by('name')
|
||||
background = BackgroundImage.get_active() if BackgroundImage.objects.exists() else None
|
||||
return render(request, 'cards/print.html', {'cards': qs, 'background': background})
|
||||
|
||||
|
||||
def print_preview(request):
|
||||
"""Render a printable view of selected cards.
|
||||
|
||||
POST params:
|
||||
- cards: repeated card pks
|
||||
- design: design number
|
||||
- scale: optional scale factor
|
||||
|
||||
Returns an HTML A4-friendly document that the browser can print or save as PDF.
|
||||
"""
|
||||
# Accept POST or GET for easier testing
|
||||
data = request.POST if request.method == 'POST' else request.GET
|
||||
pks = data.getlist('cards')
|
||||
if not pks:
|
||||
return HttpResponseBadRequest('No cards selected')
|
||||
try:
|
||||
design = int(data.get('design', '1'))
|
||||
except Exception:
|
||||
design = 1
|
||||
scale = float(data.get('scale', '1')) if data.get('scale') else 1.0
|
||||
# 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)
|
||||
pages = []
|
||||
per_page = 2
|
||||
for i in range(0, len(ordered), per_page):
|
||||
pages.append(ordered[i:i+per_page])
|
||||
|
||||
return render(request, 'cards/printable.html', {'pages': pages, 'design': design, 'scale': scale})
|
||||
|
||||
|
||||
def _parse_pasted_input(text):
|
||||
"""Try to parse pasted LLM output into a list of suggestion dicts.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user