Skip to content

Commit

Permalink
Fix tree-cards
Browse files Browse the repository at this point in the history
To allow for the fact that we now have None for one of the prices
  • Loading branch information
hyanwong committed Apr 16, 2024
1 parent d6fa56a commit 2927d1b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 6 additions & 6 deletions controllers/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)



Expand Down
2 changes: 2 additions & 0 deletions views/default/treecards.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ <h2 class="uk-text-center uk-padding-small" >How to send a Tr-eCard</h2>
{{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.</p>
<p>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.</p>
<p>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</p>
Expand Down

0 comments on commit 2927d1b

Please sign in to comment.