.
This commit is contained in:
@@ -27,6 +27,16 @@
|
|||||||
<label class="label">Scale</label>
|
<label class="label">Scale</label>
|
||||||
<div class="control"><input class="input" type="number" name="scale" value="1" step="0.05" min="0.5" max="2"></div>
|
<div class="control"><input class="input" type="number" name="scale" value="1" step="0.05" min="0.5" max="2"></div>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="label">Cards per page</label>
|
||||||
|
<div class="select">
|
||||||
|
<select name="per_page">
|
||||||
|
<option value="1">1</option>
|
||||||
|
<option value="2" selected>2</option>
|
||||||
|
<option value="4">4</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div style="margin-left:auto">
|
<div style="margin-left:auto">
|
||||||
<button class="button is-primary" type="submit">Open printable view</button>
|
<button class="button is-primary" type="submit">Open printable view</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -20,6 +20,21 @@
|
|||||||
.toptrump-card.design-3,
|
.toptrump-card.design-3,
|
||||||
.toptrump-card.design-5 { width: 98%; min-height: 120mm; }
|
.toptrump-card.design-5 { width: 98%; min-height: 120mm; }
|
||||||
.toptrump-card.design-4 { width: 98%; min-height: 135mm; }
|
.toptrump-card.design-4 { width: 98%; min-height: 135mm; }
|
||||||
|
|
||||||
|
/* Per-page adjustments: if rendering 4-up we reduce min-heights so cards fit */
|
||||||
|
{% if per_page == 4 %}
|
||||||
|
.toptrump-card.design-1,
|
||||||
|
.toptrump-card.design-2,
|
||||||
|
.toptrump-card.design-3,
|
||||||
|
.toptrump-card.design-5 { min-height: 62mm; }
|
||||||
|
.toptrump-card.design-4 { min-height: 70mm; }
|
||||||
|
{% elif per_page == 1 %}
|
||||||
|
.toptrump-card.design-1,
|
||||||
|
.toptrump-card.design-2,
|
||||||
|
.toptrump-card.design-3,
|
||||||
|
.toptrump-card.design-5 { min-height: 180mm; }
|
||||||
|
.toptrump-card.design-4 { min-height: 220mm; }
|
||||||
|
{% endif %}
|
||||||
/* Ensure hero images scale inside print cards */
|
/* Ensure hero images scale inside print cards */
|
||||||
.print-card .hero-image{height:auto; min-height:40mm;}
|
.print-card .hero-image{height:auto; min-height:40mm;}
|
||||||
.print-card img.card-hero-img{max-width:100%; height:auto; object-fit:contain}
|
.print-card img.card-hero-img{max-width:100%; height:auto; object-fit:contain}
|
||||||
@@ -87,7 +102,7 @@
|
|||||||
|
|
||||||
{% for page_cards in pages %}
|
{% for page_cards in pages %}
|
||||||
<div class="sheet">
|
<div class="sheet">
|
||||||
<div class="cards-grid">
|
<div class="cards-grid" style="grid-template-columns: repeat({{ columns|default:2 }}, 1fr); gap:8mm;">
|
||||||
{% for card in page_cards %}
|
{% for card in page_cards %}
|
||||||
<div class="print-card">
|
<div class="print-card">
|
||||||
{% if design == 1 %}
|
{% if design == 1 %}
|
||||||
|
|||||||
+18
-3
@@ -439,23 +439,38 @@ def print_preview(request):
|
|||||||
except Exception:
|
except Exception:
|
||||||
design = 1
|
design = 1
|
||||||
scale = float(data.get('scale', '1')) if data.get('scale') else 1.0
|
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
|
# Fetch cards preserving the given order
|
||||||
cards = list(Dinosaur.objects.filter(pk__in=pks))
|
cards = list(Dinosaur.objects.filter(pk__in=pks))
|
||||||
# Reorder according to provided pks
|
# Reorder according to provided pks
|
||||||
pk_to_card = {str(c.pk): c for c in cards}
|
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]
|
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 = []
|
pages = []
|
||||||
per_page = 2
|
|
||||||
for i in range(0, len(ordered), per_page):
|
for i in range(0, len(ordered), per_page):
|
||||||
pages.append(ordered[i:i+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
|
# Include the active background (if any) so fragments that fall back to
|
||||||
# a global `background` variable can render correctly in the printable view.
|
# a global `background` variable can render correctly in the printable view.
|
||||||
background = BackgroundImage.get_active() if BackgroundImage.objects.exists() else None
|
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):
|
def _parse_pasted_input(text):
|
||||||
|
|||||||
Reference in New Issue
Block a user