Files
notifications-admin/notifications_utils/countries/data.py
Alex Janousek 6f5750f095 Removed all govuk css (#2814)
* Removed all govuk css

* Updated reference files

* Removing govuk js

* Fixed casing for modules, removed unused page

* Got more reference images

* Updated template page

* Removed govuk padding util

* Updated hint to uswds hint

* More govuk cleanup

* Commiting backstopjs ref files

* Fixed all unit tests that broke due to brittleness around govuk styling

* Added new ref images

* Final removal of govuk

* Officially removed all govuk references

* Updated reference file

* Updated link to button

* UI modernization

* Cleanup

* removed govuk escaping tests since they are no longer needed

* Fix CodeQL security issue in escapeElementName function

- Escape backslashes first before other special characters
- Prevents potential double-escaping vulnerability
- Addresses CodeQL alert about improper string escaping

* Found more govuk removal. Fixed unit tests

* Add missing pipeline check to pre-commit

* updated test

* Updated e2e test

* More update to e2e test

* Fixed another e2e test

* Simple PR comments addressed

* More updates

* Updated backstop ref files

* Refactored folder selection for non-admins

* Updated redundant line

* Updated tests to include correct mocks

* Added more ref files

* Addressing carlos comments

* Addressing Carlo comments, cleanup of window initing

* More cleanup and addressing carlo comments

* Fixing a11 scan

* Fixed a few issues with javascript

* Fixed for pr

* Fixing e2e tests

* Tweaking e2e test

* Added more ref files and cleaned up urls.js

* Fixed bug with creating new template

* Removed brittle test - addressed code ql comment

* e2e race condition fix

* More e2e test fixes

* Updated e2e tests to not wait for text sent

* Updated test to not wait for button click response

* Made tear down more resilent if staging is down

* reverted e2e test to what was working before main merge

* Updated backstopRef images

* Updated gulp to include job-polling differently
2025-10-06 09:38:54 -04:00

64 lines
2.0 KiB
Python

import json
import os
def _load_data(filename):
with open(os.path.join(os.path.dirname(__file__), "_data", filename)) as contents:
if filename.endswith(".json"):
return json.load(contents)
return [line.strip() for line in contents.readlines()]
def find_canonical(item, graph, key):
if item["meta"]["canonical"]:
return key, item["names"]["en-GB"]
return find_canonical(
graph[item["edges"]["from"][0]],
graph,
key,
)
_graph = _load_data("location-autocomplete-graph.json")
UK = "United Kingdom"
ENDED_COUNTRIES = _load_data("ended-countries.json")
ADDITIONAL_SYNONYMS = list(_load_data("synonyms.json").items())
WELSH_NAMES = list(_load_data("welsh-names.json").items())
_UK_ISLANDS_LIST = _load_data("uk-islands.txt")
_EUROPEAN_ISLANDS_LIST = _load_data("european-islands.txt")
CURRENT_AND_ENDED_COUNTRIES_AND_TERRITORIES = [
find_canonical(item, _graph, item["names"]["en-GB"]) for item in _graph.values()
]
COUNTRIES_AND_TERRITORIES = []
for synonym, canonical in CURRENT_AND_ENDED_COUNTRIES_AND_TERRITORIES:
if canonical in _UK_ISLANDS_LIST:
COUNTRIES_AND_TERRITORIES.append((synonym, UK))
elif canonical in ENDED_COUNTRIES:
succeeding_country = ENDED_COUNTRIES[canonical]
if succeeding_country:
COUNTRIES_AND_TERRITORIES.append((synonym, succeeding_country))
COUNTRIES_AND_TERRITORIES.append((canonical, succeeding_country))
else:
COUNTRIES_AND_TERRITORIES.append((synonym, canonical))
UK_ISLANDS = [(synonym, UK) for synonym in _UK_ISLANDS_LIST]
EUROPEAN_ISLANDS = [(synonym, synonym) for synonym in _EUROPEAN_ISLANDS_LIST]
# Copied from https://www.royalmail.com/international-zones#europe
# Modified to use the canonical names for countries where incorrect
ROYAL_MAIL_EUROPEAN = _load_data("europe.txt")
class Postage:
UK = "united-kingdom"
FIRST = "first"
SECOND = "second"
EUROPE = "europe"
REST_OF_WORLD = "rest-of-world"