From f7f0675d26f0fde321e181d89c644c17e5a66481 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Mon, 2 Oct 2023 20:39:10 +0200 Subject: [PATCH] update to django 4.2;updated language switcher --- docker/main/requirements.txt | 2 +- gawa/gawa/settings.py | 1 - gawa/gawa/urls.py | 2 +- gawa/start/middleware.py | 26 ------ gawa/start/templates/nav.html | 118 +++++++++++++++++-------- gawa/start/templatetags/helper_tags.py | 28 ------ gawa/start/urls.py | 2 - gawa/start/views.py | 17 +--- 8 files changed, 85 insertions(+), 111 deletions(-) delete mode 100644 gawa/start/middleware.py diff --git a/docker/main/requirements.txt b/docker/main/requirements.txt index 31fb00a..99f0877 100644 --- a/docker/main/requirements.txt +++ b/docker/main/requirements.txt @@ -1,4 +1,4 @@ -Django>=3.0,<4.0 +Django>=4.0,<5.0 psycopg2>=2.8 mysqlclient>=1.4.3 django_compressor>=2.2 diff --git a/gawa/gawa/settings.py b/gawa/gawa/settings.py index 4c65909..3a39936 100644 --- a/gawa/gawa/settings.py +++ b/gawa/gawa/settings.py @@ -63,7 +63,6 @@ MIDDLEWARE = [ 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.locale.LocaleMiddleware', - 'start.middleware.LangBasedOnUrlMiddleware', ] ROOT_URLCONF = 'gawa.urls' diff --git a/gawa/gawa/urls.py b/gawa/gawa/urls.py index e748c58..a6566cf 100644 --- a/gawa/gawa/urls.py +++ b/gawa/gawa/urls.py @@ -21,7 +21,7 @@ from django.conf import settings from django.conf.urls.static import static urlpatterns = [ - re_path(r'^i18n/', include('django.conf.urls.i18n')), + re_path('i18n/', include('django.conf.urls.i18n')), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns += i18n_patterns( diff --git a/gawa/start/middleware.py b/gawa/start/middleware.py deleted file mode 100644 index a2d286c..0000000 --- a/gawa/start/middleware.py +++ /dev/null @@ -1,26 +0,0 @@ -from django.shortcuts import HttpResponse, HttpResponseRedirect -from django.utils import translation -from django.conf import settings -from django.utils.deprecation import MiddlewareMixin -from django.utils.regex_helper import re -from .forms import MainSearchForm -from .views import MainSearch - - -class LangBasedOnUrlMiddleware(MiddlewareMixin): - """ - used for switching the language - """ - @staticmethod - def process_request(request): - - if hasattr(request, 'session'): - active_session_lang = request.session.get( - translation.LANGUAGE_SESSION_KEY) - - if active_session_lang == request.LANGUAGE_CODE: - return - - if any(request.LANGUAGE_CODE in language for language in settings.LANGUAGES): - translation.activate(request.LANGUAGE_CODE) - request.session[translation.LANGUAGE_SESSION_KEY] = request.LANGUAGE_CODE diff --git a/gawa/start/templates/nav.html b/gawa/start/templates/nav.html index 186c4c6..60535e4 100644 --- a/gawa/start/templates/nav.html +++ b/gawa/start/templates/nav.html @@ -1,62 +1,108 @@ {% load i18n %} -{% load helper_tags %}