This commit is contained in:
Ross
2025-12-06 22:54:55 +00:00
parent 2dc1631fd2
commit e541e4cc31
3 changed files with 67 additions and 36 deletions
+25
View File
@@ -456,6 +456,31 @@ def print_preview(request):
for i in range(0, len(ordered), per_page):
pages.append(ordered[i:i+per_page])
# -- Top-trump calculation across the full selection -----------------
# For each card compute its best stat percent (0-100) and the stat(s)
# that achieve that percent. Then find the global maximum best-value and
# mark any card whose best-value equals that maximum as a top-trump.
all_best_values = []
for c in ordered:
# compute percents using model helpers
s = c.speed_percent()
w = c.weight_percent()
it = c.intelligence_percent()
h = c.height_percent()
# map names to values
stats = {'speed': s, 'weight': w, 'intelligence': it, 'height': h}
max_val = max(stats.values())
best_stats = [name for name, val in stats.items() if val == max_val]
# attach computed attributes so templates can read them
setattr(c, 'best_value', max_val)
setattr(c, 'best_stats', best_stats)
all_best_values.append(max_val)
# determine global maximum and mark cards as top-trump if they match
global_max = max(all_best_values) if all_best_values else 0
for c in ordered:
setattr(c, 'is_top_trump', getattr(c, 'best_value', 0) == global_max)
# ---------------------------------------------------------------------
# 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