From 4cf8f96ca77fe5491e4208e4d24a3f35174fd4f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Ba=C3=B1ados=20Schwerter?= Date: Mon, 21 Oct 2024 21:22:52 +0000 Subject: [PATCH] Collected paradigm generation code and relabelling out of frontend --- frontend/js/paradigm.js | 2 +- .../frontend/templates/morphodict/word-detail.html | 4 ++-- src/morphodict/paradigm/apps.py | 5 +++++ src/morphodict/{frontend => paradigm}/ensure_data.py | 0 .../morphodict/components/paradigm-label-switcher.html | 0 .../morphodict/components/paradigm-size-button.html | 0 .../templates/morphodict/components/paradigm.html | 0 src/morphodict/paradigm/urls.py | 2 +- src/morphodict/relabelling/apps.py | 5 +++++ .../{frontend => relabelling}/templatetags/relabelling.py | 0 .../templatetags/test_relabelling.py | 0 src/morphodict/site/settings.py | 2 ++ src/morphodict/tests/test_views.py | 6 +++--- 13 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 src/morphodict/paradigm/apps.py rename src/morphodict/{frontend => paradigm}/ensure_data.py (100%) rename src/morphodict/{frontend => paradigm}/templates/morphodict/components/paradigm-label-switcher.html (100%) rename src/morphodict/{frontend => paradigm}/templates/morphodict/components/paradigm-size-button.html (100%) rename src/morphodict/{frontend => paradigm}/templates/morphodict/components/paradigm.html (100%) create mode 100644 src/morphodict/relabelling/apps.py rename src/morphodict/{frontend => relabelling}/templatetags/relabelling.py (100%) rename src/morphodict/{frontend => relabelling}/templatetags/test_relabelling.py (100%) diff --git a/frontend/js/paradigm.js b/frontend/js/paradigm.js index a514b5ab4..067d9f1c2 100644 --- a/frontend/js/paradigm.js +++ b/frontend/js/paradigm.js @@ -45,7 +45,7 @@ function setupParadigmSizeToggleButton(currentParadigmSize) { displayButtonAsLoading(toggleButton); fetch( - window.Urls["cree-dictionary-paradigm-detail"]() + + window.Urls["morphodict-paradigm-detail"]() + `?lemma-id=${lemmaId}¶digm-size=${nextParadigmSize}` ) .then((r) => { diff --git a/src/morphodict/frontend/templates/morphodict/word-detail.html b/src/morphodict/frontend/templates/morphodict/word-detail.html index 26aec00d4..e26d8432b 100644 --- a/src/morphodict/frontend/templates/morphodict/word-detail.html +++ b/src/morphodict/frontend/templates/morphodict/word-detail.html @@ -71,8 +71,8 @@

{% if paradigm %} - {% include './components/paradigm-label-switcher.html' %} - {% include './components/paradigm.html' %} + {% include 'morphodict/components/paradigm-label-switcher.html' %} + {% include 'morphodict/components/paradigm.html' %} {% endif %}
diff --git a/src/morphodict/paradigm/apps.py b/src/morphodict/paradigm/apps.py new file mode 100644 index 000000000..2d70ac38d --- /dev/null +++ b/src/morphodict/paradigm/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class ParadigmConfig(AppConfig): + name = "morphodict.paradigm" diff --git a/src/morphodict/frontend/ensure_data.py b/src/morphodict/paradigm/ensure_data.py similarity index 100% rename from src/morphodict/frontend/ensure_data.py rename to src/morphodict/paradigm/ensure_data.py diff --git a/src/morphodict/frontend/templates/morphodict/components/paradigm-label-switcher.html b/src/morphodict/paradigm/templates/morphodict/components/paradigm-label-switcher.html similarity index 100% rename from src/morphodict/frontend/templates/morphodict/components/paradigm-label-switcher.html rename to src/morphodict/paradigm/templates/morphodict/components/paradigm-label-switcher.html diff --git a/src/morphodict/frontend/templates/morphodict/components/paradigm-size-button.html b/src/morphodict/paradigm/templates/morphodict/components/paradigm-size-button.html similarity index 100% rename from src/morphodict/frontend/templates/morphodict/components/paradigm-size-button.html rename to src/morphodict/paradigm/templates/morphodict/components/paradigm-size-button.html diff --git a/src/morphodict/frontend/templates/morphodict/components/paradigm.html b/src/morphodict/paradigm/templates/morphodict/components/paradigm.html similarity index 100% rename from src/morphodict/frontend/templates/morphodict/components/paradigm.html rename to src/morphodict/paradigm/templates/morphodict/components/paradigm.html diff --git a/src/morphodict/paradigm/urls.py b/src/morphodict/paradigm/urls.py index 391625b0e..3444f205f 100644 --- a/src/morphodict/paradigm/urls.py +++ b/src/morphodict/paradigm/urls.py @@ -8,6 +8,6 @@ path( "_paradigm_details/", views.paradigm_internal, - name="cree-dictionary-paradigm-detail", + name="morphodict-paradigm-detail", ), ] \ No newline at end of file diff --git a/src/morphodict/relabelling/apps.py b/src/morphodict/relabelling/apps.py new file mode 100644 index 000000000..8e0bb7c90 --- /dev/null +++ b/src/morphodict/relabelling/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class RelabellingConfig(AppConfig): + name = "morphodict.relabelling" diff --git a/src/morphodict/frontend/templatetags/relabelling.py b/src/morphodict/relabelling/templatetags/relabelling.py similarity index 100% rename from src/morphodict/frontend/templatetags/relabelling.py rename to src/morphodict/relabelling/templatetags/relabelling.py diff --git a/src/morphodict/frontend/templatetags/test_relabelling.py b/src/morphodict/relabelling/templatetags/test_relabelling.py similarity index 100% rename from src/morphodict/frontend/templatetags/test_relabelling.py rename to src/morphodict/relabelling/templatetags/test_relabelling.py diff --git a/src/morphodict/site/settings.py b/src/morphodict/site/settings.py index fa7e1c198..80ba694b7 100644 --- a/src/morphodict/site/settings.py +++ b/src/morphodict/site/settings.py @@ -75,12 +75,14 @@ "morphodict.lexicon", # Internal apps # TODO: our internal app organization is kind of a mess 🙃 + "morphodict.relabelling", "morphodict.api", "morphodict.frontend", "morphodict.cvd", "morphodict.search_quality", "morphodict.phrase_translate", "morphodict.orthography", + "morphodict.paradigm", # This comes last so that other apps can override templates "django.contrib.admin", ] diff --git a/src/morphodict/tests/test_views.py b/src/morphodict/tests/test_views.py index d915cd99b..660765be2 100644 --- a/src/morphodict/tests/test_views.py +++ b/src/morphodict/tests/test_views.py @@ -52,14 +52,14 @@ def test_paradigm_details_internal_400_404( get_data["lemma-id"] = lemma_id if paradigm_size is not None: get_data["paradigm-size"] = paradigm_size - response = c.get(reverse("cree-dictionary-paradigm-detail"), get_data) + response = c.get(reverse("morphodict-paradigm-detail"), get_data) assert response.status_code == expected_code @pytest.mark.parametrize(("method",), (("post",), ("put",), ("delete",))) def test_paradigm_details_internal_wrong_method(self, method: str): c = Client() response = getattr(c, method)( - reverse("cree-dictionary-paradigm-detail"), + reverse("morphodict-paradigm-detail"), {"lemma-id": 1, "paradigm-size": "BASIC"}, ) assert response.status_code == HttpResponseNotAllowed.status_code @@ -146,7 +146,7 @@ def test_paradigm_from_full_page_and_api(client: Client): # Get fragment from API request: response = client.get( - reverse("cree-dictionary-paradigm-detail"), + reverse("morphodict-paradigm-detail"), cast( Dict[str, int | str], {