translator_directory.utils

Functions

to_tuple(→ tuple[float, float])

found_route(→ bool)

out_of_tolerance(→ bool)

Checks if distances are off by +- a factor, but returns False if a

validate_geocode_result(→ RealCoordinates | None)

parse_directions_result(→ float)

same_coords(→ bool)

update_drive_distances(→ tuple[int, int, int, ...)

Handles updating Translator.driving_distance. Can be used in a cli or view.

geocode_translator_addresses(→ tuple[int, int, int, ...)

nationality_choices(→ list[wtforms.fields.choices._Choice])

country_code_to_name(→ dict[str, str])

Returns a dict of country codes mapped to its country names according

get_custom_text(→ str)

Returns a custom text from the app's custom_texts dict.

Module Contents

translator_directory.utils.to_tuple(coordinate: onegov.gis.models.coordinates.RealCoordinates) tuple[float, float][source]
translator_directory.utils.found_route(response: requests.Response) bool[source]
translator_directory.utils.out_of_tolerance(old_distance: float | None, new_distance: float | None, tolerance_factor: float, max_tolerance: float | None = None) bool[source]

Checks if distances are off by +- a factor, but returns False if a set max_tolerance is not exceeded.

translator_directory.utils.validate_geocode_result(response: requests.Response, zip_code: str | int | None, zoom: int | None = None, bbox: Collection[RealCoordinates] | None = None) RealCoordinates | None[source]
translator_directory.utils.parse_directions_result(response: requests.Response) float[source]
translator_directory.utils.same_coords(this: onegov.gis.Coordinates, other: onegov.gis.Coordinates) bool[source]
translator_directory.utils.update_drive_distances(request: onegov.translator_directory.request.TranslatorAppRequest, only_empty: bool, tolerance_factor: float = 0.1, max_tolerance: float | None = None, max_distance: float | None = None) tuple[int, int, int, list[onegov.translator_directory.models.translator.Translator], list[tuple[onegov.translator_directory.models.translator.Translator, float]]][source]

Handles updating Translator.driving_distance. Can be used in a cli or view.

translator_directory.utils.geocode_translator_addresses(request: onegov.translator_directory.request.TranslatorAppRequest, only_empty: bool, bbox: Collection[RealCoordinates] | None = None) tuple[int, int, int, int, list[onegov.translator_directory.models.translator.Translator]][source]
translator_directory.utils.nationality_choices(locale: str | None) list[wtforms.fields.choices._Choice][source]
translator_directory.utils.country_code_to_name(locale: str | None) dict[str, str][source]

Returns a dict of country codes mapped to its country names according the given locale.

Example:

{‘CH’: ‘Switzerland’, ‘DE’: ‘Germany, …}

translator_directory.utils.get_custom_text(request: onegov.org.request.OrgRequest, key: str) str[source]

Returns a custom text from the app’s custom_texts dict.