From 2927d1bf228eb83ac2dd201ad83cd2e835c9b0da Mon Sep 17 00:00:00 2001
From: Yan Wong
Date: Tue, 16 Apr 2024 14:09:23 +0100
Subject: [PATCH] Fix tree-cards
To allow for the fact that we now have None for one of the prices
---
controllers/default.py | 12 ++++++------
views/default/treecards.html | 2 ++
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/controllers/default.py b/controllers/default.py
index 387da271..68487138 100755
--- a/controllers/default.py
+++ b/controllers/default.py
@@ -1176,14 +1176,14 @@ def treecards():
prices = []
accumulate = 0
for row in db(db.prices).select(db.prices.ALL, orderby=db.prices.price):
- accumulate += row.n_leaves
- prices.append(
- {'price_pounds': row.price/100, 'n': row.n_leaves, 'cumulative': accumulate})
+ if row.price is not None and row.n_leaves > 0:
+ accumulate += row.n_leaves
+ prices.append(
+ {'price_pounds': row.price/100, 'n': row.n_leaves, 'cumulative': accumulate})
for p in prices:
p['quantile'] = p['cumulative']/accumulate
- return dict(
- pick=sponsor_picks(sponsor_suggestion=sponsor_suggestion_flags['sponsor_for']),
- prices=prices)
+ suggest = sponsor_suggestion_flags['sponsor_for']
+ return dict(pick=sponsor_picks(sponsor_suggestion=suggest), prices=prices)
diff --git a/views/default/treecards.html b/views/default/treecards.html
index 8d2a2685..a43afc1a 100755
--- a/views/default/treecards.html
+++ b/views/default/treecards.html
@@ -40,7 +40,9 @@ How to send a Tr-eCard
{{else:}}or {{=fmt_pounds(p['price_pounds'])}} to sponsor
{{break}}
{{pass}}
+ {{if len(prices) > 1:}}
(roughly {{="{:.1g}".format((prices[-1]['quantile']-prices[-2]['quantile']) * 100)}}% are in the top bracket of {{=fmt_pounds(prices[-1]['price_pounds'])}}).
+ {{pass}}
With over two million leaves, there's something for everyone.
If you find your species whilst exploring the tree, zoom in and click on it to bring up a menu; one of the options will be to sponsor. You can also find your species from the menus on this page, clicking on it will take you straight to the sponsorship form. Once you get to the sponsorship form just follow the instructions.
Your text will need to be verified to appear on the public tree, once this has been done you will receive an e-mail with a link. You can then send this on to the recipient of your Tr-eCard