diff --git a/src/humulus/filters.py b/src/humulus/filters.py index a8e2d24..8064afb 100644 --- a/src/humulus/filters.py +++ b/src/humulus/filters.py @@ -134,6 +134,21 @@ def sort_hops(hops, form=False): return hops_sorted +def ferm_pct(fermentables): + """Adds a 'pct' to each fermentable in fermentables. + + 'pct' represents the total percentage a fermentable makes up of the grist. + """ + total = 0 + # Calculate total + for ferm in fermentables: + total += float(ferm['amount']) + # Add a pct to each ferm + for ferm in fermentables: + ferm['pct'] = 100*float(ferm['amount'])/total + return fermentables + + def create_filters(app): app.add_template_filter(recipe_og) app.add_template_filter(recipe_fg) @@ -142,3 +157,4 @@ def create_filters(app): app.add_template_filter(recipe_abv) app.add_template_filter(recipe_srm) app.add_template_filter(sort_hops) + app.add_template_filter(ferm_pct) diff --git a/src/humulus/templates/recipes/info.html b/src/humulus/templates/recipes/info.html index ca8a46b..6264a85 100644 --- a/src/humulus/templates/recipes/info.html +++ b/src/humulus/templates/recipes/info.html @@ -122,14 +122,16 @@