From f35410f4c9318262b755ea298c58cb84eea0beff Mon Sep 17 00:00:00 2001 From: Sym Roe Date: Mon, 15 Apr 2024 11:49:07 +0100 Subject: [PATCH] Link to official sites where possible --- .../templates/includes/ballot_model.html | 1 + postcode_lookup/utils.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) 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]