Skip to content

Commit

Permalink
Link to official sites where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
symroe committed Apr 15, 2024
1 parent bae19bc commit f35410f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions postcode_lookup/templates/includes/ballot_model.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
{% else %}
<p>This election takes place on <time datetime=&quot;{{ ballot.poll_open_date }}&quot;>{{ ballot.poll_open_date.strftime('%-d %B %Y') }}</time>.
<a href=&quot;/i-am-a/voter/types-elections&quot;>Find out more about voting in this election</a>.</p>
{{ additional_ballot_link(request, ballot) }}
{% endif %}


Expand Down
19 changes: 19 additions & 0 deletions postcode_lookup/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""<p><a href="{url}" class="o-external-link">Find out more about this election at {label}</a></p>"""


class _i18nJinja2Templates(Jinja2Templates):
locale = None

Expand All @@ -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]
Expand Down

0 comments on commit f35410f

Please sign in to comment.