diff --git a/postcode_lookup/templates/includes/ballot_model.html b/postcode_lookup/templates/includes/ballot_model.html index ae748e0..6b2967d 100644 --- a/postcode_lookup/templates/includes/ballot_model.html +++ b/postcode_lookup/templates/includes/ballot_model.html @@ -15,6 +15,7 @@ {% else %}

This election takes place on . Find out more about voting in this election.

+ {{ additional_ballot_link(request, ballot) }} {% endif %} diff --git a/postcode_lookup/utils.py b/postcode_lookup/utils.py index 897f257..80b1d34 100644 --- a/postcode_lookup/utils.py +++ b/postcode_lookup/utils.py @@ -38,6 +38,24 @@ def translated_url(request: Request, name: str) -> URL: return url +def additional_ballot_link(request, ballot) -> str: + url, label = None, None + if any( + part in ballot.ballot_paper_id + for part in ("mayor.london", "gla.a", "gla.c") + ): + url = "https://www.londonelects.org.uk/im-voter" + label = "London Elects" + if "pcc." in ballot.ballot_paper_id: + url = f"https://choosemypcc.org.uk/area/gloucestershire/?postcode={request.query_params.get('postcode-search')}" + label = "'Choose My PCC'" + + if not all((url, label)): + return "" + + return f"""

Find out more about this election at {label}

""" + + class _i18nJinja2Templates(Jinja2Templates): locale = None @@ -52,6 +70,7 @@ def _create_env( env.filters["date_filter"] = date_format env.policies["ext.i18n.trimmed"] = True env.globals["translated_url"] = translated_url + env.globals["additional_ballot_link"] = additional_ballot_link locale_dir = Path(__file__).parent / "locale" list_of_desired_locales = [self.locale]