From d5e6589df096f675496b64ccec3a05c2472c1be9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Reuiller?= Date: Fri, 26 Apr 2024 18:10:38 +0200 Subject: [PATCH 1/4] add home page processors --- config/settings/base.py | 4 ++++ lemarche/utils/home_page_context_processors.py | 17 +++++++++++++++++ lemarche/utils/settings_context_processors.py | 1 + lemarche/www/siaes/tests.py | 2 +- 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 lemarche/utils/home_page_context_processors.py diff --git a/config/settings/base.py b/config/settings/base.py index e5fbbf1a1..5b8ba07a4 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -205,6 +205,7 @@ "django.contrib.messages.context_processors.messages", # custom "lemarche.utils.settings_context_processors.expose_settings", + "lemarche.utils.home_page_context_processors.home_page", ], }, }, @@ -863,6 +864,9 @@ WAGTAIL_FRONTEND_LOGIN_URL = LOGIN_URL +# Specific home page is setted here to avoid one query on every page +SIAE_HOME_PAGE = "/accueil-structure" + # Increase throttling to avoid Bad request errors when saving large pages # https://docs.djangoproject.com/en/4.2/ref/settings/#data-upload-max-number-fields DATA_UPLOAD_MAX_NUMBER_FIELDS = env.int("DATA_UPLOAD_MAX_NUMBER_FIELDS", 10000) diff --git a/lemarche/utils/home_page_context_processors.py b/lemarche/utils/home_page_context_processors.py new file mode 100644 index 000000000..b75fe5935 --- /dev/null +++ b/lemarche/utils/home_page_context_processors.py @@ -0,0 +1,17 @@ +from django.conf import settings +from django.urls import reverse_lazy + +from lemarche.users.models import User + + +def home_page(request): + """ + Put things into the context to make them available in templates. + https://docs.djangoproject.com/en/4.2/ref/templates/api/#using-requestcontext + """ + + home_page = reverse_lazy("wagtail_serve", args=("",)) + if request.user.is_authenticated and request.user.kind == User.KIND_SIAE: + home_page = settings.SIAE_HOME_PAGE + + return {"HOME_PAGE_PATH": home_page} diff --git a/lemarche/utils/settings_context_processors.py b/lemarche/utils/settings_context_processors.py index 05384e499..d1af2c45f 100644 --- a/lemarche/utils/settings_context_processors.py +++ b/lemarche/utils/settings_context_processors.py @@ -29,4 +29,5 @@ def expose_settings(request): "TYPEFORM_GROUPEMENT_AJOUT": settings.TYPEFORM_GROUPEMENT_AJOUT, "FORM_PARTENAIRES": settings.FORM_PARTENAIRES, "MTCAPTCHA_PUBLIC_KEY": settings.MTCAPTCHA_PUBLIC_KEY, + "SIAE_HOME_PAGE": settings.SIAE_HOME_PAGE, } diff --git a/lemarche/www/siaes/tests.py b/lemarche/www/siaes/tests.py index 5cb93c0ff..5c4d3361c 100644 --- a/lemarche/www/siaes/tests.py +++ b/lemarche/www/siaes/tests.py @@ -36,7 +36,7 @@ def setUpTestData(cls): def test_search_num_queries(self): url = reverse("siae:search_results") - with self.assertNumQueries(11): + with self.assertNumQueries(8): response = self.client.get(url) siaes = list(response.context["siaes"]) self.assertEqual(len(siaes), 20) From 941c123f238f5d3f82983c8e9c70e027f9ad5d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Reuiller?= Date: Fri, 26 Apr 2024 18:16:13 +0200 Subject: [PATCH 2/4] use HOME_PAGE_PATH in templates --- config/settings/base.py | 2 +- lemarche/templates/api/home.html | 2 +- lemarche/templates/auth/login.html | 2 +- lemarche/templates/auth/password_reset.html | 2 +- lemarche/templates/auth/password_reset_confirm.html | 2 +- lemarche/templates/auth/password_reset_sent.html | 4 ++-- lemarche/templates/auth/signup.html | 2 +- lemarche/templates/cms/article_list.html | 2 +- lemarche/templates/cms/article_page.html | 2 +- lemarche/templates/cms/paid_article_list.html | 2 +- lemarche/templates/cms/static/decouvrir-inclusion.html | 2 +- lemarche/templates/cms/static/filiere_recyclage.html | 2 +- lemarche/templates/cms/static/filiere_restauration.html | 2 +- lemarche/templates/cms/static/valoriser-achats.html | 2 +- lemarche/templates/dashboard/home_buyer.html | 2 +- lemarche/templates/dashboard/home_siae.html | 2 +- lemarche/templates/dashboard/profile_edit.html | 2 +- lemarche/templates/dashboard/siae_edit_base.html | 2 +- lemarche/templates/dashboard/siae_search_adopt_confirm.html | 2 +- lemarche/templates/dashboard/siae_search_by_siret.html | 2 +- lemarche/templates/dashboard/siae_users.html | 2 +- lemarche/templates/favorites/dashboard_favorite_list.html | 2 +- .../templates/favorites/dashboard_favorite_list_detail.html | 2 +- lemarche/templates/includes/_header_for_buyers.html | 2 +- lemarche/templates/includes/_header_for_siaes.html | 2 +- lemarche/templates/layouts/_footer.html | 2 +- lemarche/templates/layouts/_header.html | 4 ++-- lemarche/templates/layouts/_header_nav_secondary_items.html | 2 +- lemarche/templates/networks/dashboard_network_siae_list.html | 2 +- .../networks/dashboard_network_siae_tender_list.html | 2 +- .../templates/networks/dashboard_network_tender_detail.html | 2 +- .../templates/networks/dashboard_network_tender_list.html | 2 +- .../networks/dashboard_network_tender_siae_list.html | 2 +- lemarche/templates/pages/accessibilite.html | 2 +- lemarche/templates/pages/company-reference-calculator.html | 2 +- lemarche/templates/pages/contact.html | 2 +- lemarche/templates/pages/decouvrir-inclusion.html | 2 +- lemarche/templates/pages/filiere_recyclage.html | 2 +- lemarche/templates/pages/filiere_restauration.html | 2 +- lemarche/templates/pages/flatpage_template.html | 2 +- lemarche/templates/pages/groupements.html | 2 +- lemarche/templates/pages/impact-calculator.html | 2 +- lemarche/templates/pages/partenaires.html | 2 +- lemarche/templates/pages/social-impact-for-buyers.html | 2 +- lemarche/templates/pages/stats.html | 2 +- lemarche/templates/pages/valoriser-achats.html | 2 +- lemarche/templates/siaes/detail.html | 2 +- lemarche/templates/siaes/search_results.html | 2 +- lemarche/templates/tenders/create_base.html | 2 +- lemarche/templates/tenders/detail.html | 2 +- lemarche/templates/tenders/list.html | 2 +- lemarche/templates/tenders/siae_interested_list.html | 2 +- lemarche/templates/tenders/survey_transactioned_detail.html | 2 +- 53 files changed, 55 insertions(+), 55 deletions(-) diff --git a/config/settings/base.py b/config/settings/base.py index 5b8ba07a4..cad0436f2 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -865,7 +865,7 @@ WAGTAIL_FRONTEND_LOGIN_URL = LOGIN_URL # Specific home page is setted here to avoid one query on every page -SIAE_HOME_PAGE = "/accueil-structure" +SIAE_HOME_PAGE = "/accueil-structure/" # Increase throttling to avoid Bad request errors when saving large pages # https://docs.djangoproject.com/en/4.2/ref/settings/#data-upload-max-number-fields diff --git a/lemarche/templates/api/home.html b/lemarche/templates/api/home.html index 43822c965..f7ea9d8f1 100644 --- a/lemarche/templates/api/home.html +++ b/lemarche/templates/api/home.html @@ -10,7 +10,7 @@
diff --git a/lemarche/templates/auth/login.html b/lemarche/templates/auth/login.html index f0e7aab59..126934f9c 100644 --- a/lemarche/templates/auth/login.html +++ b/lemarche/templates/auth/login.html @@ -10,7 +10,7 @@
diff --git a/lemarche/templates/auth/password_reset.html b/lemarche/templates/auth/password_reset.html index bd66e0c74..bd0da1093 100644 --- a/lemarche/templates/auth/password_reset.html +++ b/lemarche/templates/auth/password_reset.html @@ -10,7 +10,7 @@
diff --git a/lemarche/templates/auth/password_reset_confirm.html b/lemarche/templates/auth/password_reset_confirm.html index e24c6792d..c17b8dd8b 100644 --- a/lemarche/templates/auth/password_reset_confirm.html +++ b/lemarche/templates/auth/password_reset_confirm.html @@ -10,7 +10,7 @@
diff --git a/lemarche/templates/auth/password_reset_sent.html b/lemarche/templates/auth/password_reset_sent.html index 7a78efc8e..65a93d2fc 100644 --- a/lemarche/templates/auth/password_reset_sent.html +++ b/lemarche/templates/auth/password_reset_sent.html @@ -9,7 +9,7 @@
@@ -37,7 +37,7 @@

  • vérifiez qu'il n'y a pas d'erreur dans votre e-mail
  • - + Revenir à la page principale diff --git a/lemarche/templates/auth/signup.html b/lemarche/templates/auth/signup.html index 3f1d57f38..2ff82f2b9 100644 --- a/lemarche/templates/auth/signup.html +++ b/lemarche/templates/auth/signup.html @@ -10,7 +10,7 @@

    diff --git a/lemarche/templates/cms/article_list.html b/lemarche/templates/cms/article_list.html index 28729c341..a713c1cae 100644 --- a/lemarche/templates/cms/article_list.html +++ b/lemarche/templates/cms/article_list.html @@ -11,7 +11,7 @@