From dc069559a69039b591870fee24eb26581946c86b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Ba=C3=B1ados=20Schwerter?= Date: Mon, 18 Nov 2024 23:09:22 +0000 Subject: [PATCH] Fixes for reformat_altlabel script --- .../frontend/templatetags/morphodict_extras.py | 2 +- src/morphodict/frontend/views.py | 2 +- src/morphodict/tests/test_utils.py | 2 +- src/morphodict/utils/__init__.py | 18 ------------------ src/morphodict/utils/views.py | 17 +++++++++++++++++ 5 files changed, 20 insertions(+), 21 deletions(-) create mode 100644 src/morphodict/utils/views.py diff --git a/src/morphodict/frontend/templatetags/morphodict_extras.py b/src/morphodict/frontend/templatetags/morphodict_extras.py index 2662ef05f..7290b64d6 100644 --- a/src/morphodict/frontend/templatetags/morphodict_extras.py +++ b/src/morphodict/frontend/templatetags/morphodict_extras.py @@ -15,7 +15,7 @@ observed_wordforms, ) from morphodict.relabelling import read_labels -from morphodict.utils import url_for_query +from morphodict.utils.views import url_for_query from morphodict.orthography.templatetags.morphodict_orth import orth_tag from morphodict.lexicon.models import Wordform diff --git a/src/morphodict/frontend/views.py b/src/morphodict/frontend/views.py index 111d8beee..fe344a147 100644 --- a/src/morphodict/frontend/views.py +++ b/src/morphodict/frontend/views.py @@ -19,7 +19,7 @@ from morphodict.lexicon.models import Wordform -from morphodict.utils import url_for_query +from morphodict.utils.views import url_for_query # The index template expects to be rendered in the following "modes"; # The mode dictates which variables MUST be present in the context. diff --git a/src/morphodict/tests/test_utils.py b/src/morphodict/tests/test_utils.py index c78074160..728b160b2 100644 --- a/src/morphodict/tests/test_utils.py +++ b/src/morphodict/tests/test_utils.py @@ -1,7 +1,7 @@ from string import printable as ascii_printable import pytest -from morphodict.utils import url_for_query +from morphodict.utils.views import url_for_query @pytest.mark.parametrize("query", ["awa", "wâpamêw", "ᐚᐸᒣᐤ"]) diff --git a/src/morphodict/utils/__init__.py b/src/morphodict/utils/__init__.py index 48d3e7424..afe318dd2 100644 --- a/src/morphodict/utils/__init__.py +++ b/src/morphodict/utils/__init__.py @@ -1,27 +1,9 @@ from .cree_lev_dist import get_modified_distance # Unused but exported from .shared_res_dir import shared_res_dir # Unused but exported -from urllib.parse import ParseResult, urlencode, urlunparse -from django.urls import reverse import requests import urllib - -def url_for_query(user_query: str) -> str: - """ - Produces a relative URL to search for the given user query. - """ - parts = ParseResult( - scheme="", - netloc="", - params="", - path=reverse("cree-dictionary-search"), - query=urlencode((("q", user_query),)), - fragment="", - ) - return urlunparse(parts) - - def get_recordings_from_url(search_terms, url, speech_db_eq): matched_recordings = {} query_params = [("q", term) for term in search_terms] diff --git a/src/morphodict/utils/views.py b/src/morphodict/utils/views.py new file mode 100644 index 000000000..0936a0a7f --- /dev/null +++ b/src/morphodict/utils/views.py @@ -0,0 +1,17 @@ +from urllib.parse import ParseResult, urlencode, urlunparse + +from django.urls import reverse + +def url_for_query(user_query: str) -> str: + """ + Produces a relative URL to search for the given user query. + """ + parts = ParseResult( + scheme="", + netloc="", + params="", + path=reverse("cree-dictionary-search"), + query=urlencode((("q", user_query),)), + fragment="", + ) + return urlunparse(parts) \ No newline at end of file